zoukankan      html  css  js  c++  java
  • MVC用户权限验证

    MVC用户权限验证 新增UserAuthorizeAttribute类

    using Dw.Util;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace LoanH5APP_2020.Models
    {
        /// <summary>
        /// 用户权限验证
        /// </summary>
        public class UserAuthorizeAttribute : AuthorizeAttribute
        {
            /// <summary>
            /// 判断用户是否登录成功
            /// 登录成功返回true,否者返回false
            /// 返回false将读取web.config中的loginUrl跳转到登录页面
            /// </summary>
            /// <param name="httpContext"></param>
            /// <returns></returns>
            protected override bool AuthorizeCore(HttpContextBase httpContext)
            {
                var isAuthorized = false;
                if (httpContext != null && httpContext.Session != null)
                {
                    if (httpContext.Session["User"] != null)
                    {
                        isAuthorized = true;
                    }
                }
                return isAuthorized;
            }
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                base.OnAuthorization(filterContext);
            }
        }
    }

    webconfig增加配置项 <system.web>下

    <authentication mode="Forms">
          <forms loginUrl="~/Home/PreIndex" timeout="2880" />
        </authentication>
  • 相关阅读:
    gnuplot
    charles证书安装
    jenkins 配置ssh
    jenkins 配置slave
    centos 安装jenkins
    mac的一些命令
    docker 常用命令
    GO vim环境
    go vendor目录
    protobuf
  • 原文地址:https://www.cnblogs.com/yechangzhong-826217795/p/14572127.html
Copyright © 2011-2022 走看看