• .NET MVC中登陆授权过滤器的使用


    1、写个类LoginAuthorityAttribute,继承自AuthorizeAttribute

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace PowerBIDocs.Web.Utils
    {
        public class LoginAuthorityAttribute : AuthorizeAttribute
        {
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                if (App_Start.GlobalConfig.LoginedUser == null)
                {
                    filterContext.HttpContext.Response.Redirect("~/Home/Login");
                }
            }
        }
    }

    2、在所有需要登陆才能访问的控制器中的方法上面,标注:   [LoginAuthority]

          [LoginAuthority]
            public ActionResult Logout()
            {
                HttpContext.Session[App_Start.GlobalConfig.LoginedUserSessionKey] = null;
                return RedirectToAction("Login");
            }

    3、说明:上面的例子中,用户信息存在于SESSION中。

      

  • 相关阅读:
    spark 中划分stage的思路
    如何带人
    技术管理
    学会谈判
    绩效评估与绩效反馈
    企业文化如何落地
    绩效沟通的best原则
    Area POJ
    Cows POJ
    Grandpa's Estate POJ
  • 原文地址:https://www.cnblogs.com/songxingzhu/p/7991287.html
Copyright © 2020-2023  润新知