zoukankan      html  css  js  c++  java
  • ASP.NET MVC 自己实现登陆验证过滤器

    1、首先添加一个过滤器类,并实现接口中对应的方法

    public class YLFAuthorizeAttribute : FilterAttribute, IAuthorizationFilter
    {
      public void OnAuthorization(AuthorizationContext filterContext)
      {
        //获取控制器名称     
    string control= filterContext.Controller.ToString();
        //获取Action名称     
    string action = filterContext.ActionDescriptor.ActionName;
        //判断登陆标记,如果不成功了,页面跳转     
    if (filterContext.HttpContext.Session["UserName"] == null)       filterContext.Result = new RedirectResult("/home/index");   } }

    2、将你的过滤属性添加到对应的Controller类的上方,则对此控制器内所有Action进行登陆验证,如果只添加到某个Action上,可以只对某个Action进行登陆验证。

  • 相关阅读:
    leetcode-剑指19-OK
    leetcode-剑指38-?
    leetcode-剑指36-OK
    leetcode-剑指41-OK
    leetcode-剑指20-OK
    leetcode-剑指16-OK
    nginx重写路由隐藏入口文件报错引发的思考
    Go之并发
    Go之接口
    Go实现学生管理系统
  • 原文地址:https://www.cnblogs.com/feihusurfer/p/3989785.html
Copyright © 2011-2022 走看看