• set .net principle


                var ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes), true, JsonConvert.SerializeObject(userinfo), FormsAuthentication.FormsCookiePath);
                HttpContext.Current.User = new GenericPrincipal(new FormsIdentity(ticket), null);
                var hash = FormsAuthentication.Encrypt(ticket);
                CookieHelper.SetCookie(FormsAuthentication.FormsCookieName, hash, FormsAuthentication.FormsCookiePath, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes), true, FormsAuthentication.RequireSSL);
    

      

    using System;
    using System.Web.Mvc;
    using System.Web.Routing;
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAuthenticated)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Login", action = "Login" }));
            }
            else
            {
                base.HandleUnauthorizedRequest(filterContext);
            }
        }
    }
    

      

    filterContext.Result = new RedirectToRouteResult(
                            new RouteValueDictionary(
                                new
                                {
                                    controller = "Login",
                                    action = "Login",
                                    returnUrl = filterContext.HttpContext.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped)
                                }));
    

      

  • 相关阅读:
    数据结构(2)-链表
    数据结构(1)-数组
    SpringMVC学习总结(一)--Hello World入门
    基本数据类型对象的包装类
    关于String的相关常见方法
    常见的集合容器应当避免的坑
    再一次生产 CPU 高负载排查实践
    分表后需要注意的二三事
    线程池没你想的那么简单(续)
    线程池没你想的那么简单
  • 原文地址:https://www.cnblogs.com/hualiu0/p/6340454.html
Copyright © 2020-2023  润新知