zoukankan      html  css  js  c++  java
  • 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)
                                }));
    

      

  • 相关阅读:
    每日日报110
    每日日报109
    每日日报108
    每日日报107
    每日日报106
    每日日报105
    每日日报104
    eclipse新建Maven Project项目后出现The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path问题的解决办法
    0proxy/reflect
    toRefs/toRef/unref/customRef
  • 原文地址:https://www.cnblogs.com/hualiu0/p/6340454.html
Copyright © 2011-2022 走看看