zoukankan      html  css  js  c++  java
  • asp.net 在AcquireRequestState事件中判断登陆验证。

    Global中添加AcquireRequestState事件。

    protected void Application_AcquireRequestState(object sender, EventArgs e)
    {
        Uri url = Request.Url;  //得到当前请求的URL
        //访问Admin目录,需要进行登陆验证。
        if (url.AbsolutePath.ToLower().StartsWith("/admin"))
        {
            //如果Login.aspx写在admin目录下,需要排除对Login.aspx验证。
    
            if (HttpContext.Current.Session["Name"] == null)
            {
                HttpContext.Current.Response.Redirect("~/Login.aspx");
            }
        }
    }

    也可以使用IHttpModule接口,创建一个类,在配置文件中调用下。

    //不要忘记:在配置文件中配置一下。
    //<httpModules>
    //    <add name="CheckAdminModule" type="Web.Common.CheckAdminModule"/>
    //</httpModules>

    public class CheckAdminModule:IHttpModule
    {
      public void Init(HttpApplication context)
      {
        context.AcquireRequestState += new EventHandler(OnAcquireRequestState);  
      }
    
      public void OnAcquireRequestState(object sender, EventArgs e)
      {
        HttpApplication application = sender as HttpApplication;
        Uri url = application.Request.Url;  //得到当前请求的URL
        //访问Admin目录,需要进行登陆验证。
        if (url.AbsolutePath.ToLower().StartsWith("/admin"))
        {
          //如果Login.aspx写在admin目录下,需要排除对Login.aspx验证。
          if (application.Session["Name"] == null) //HttpContext.Current.Session["Name"]
          {
            application.Response.Redirect("~/Login.aspx");
          }
        }
      }
    }
  • 相关阅读:
    Linux-安装FFmpeg
    博客园添加视频
    博客园添加音乐
    通过容器提交镜像(docker commit)以及推送镜像(docker push)笔记
    根据不同配置.env获取不同的配置文件的配置
    1M大概多少个字
    计算机存储单位
    DNS原理及其解析过程
    查看到百度经过了多少个网关
    C语言的本质(18)——函数的可变参数
  • 原文地址:https://www.cnblogs.com/han1982/p/4080326.html
Copyright © 2011-2022 走看看