zoukankan      html  css  js  c++  java
  • 给管道注册事件,用于用户是否登录!

    1.一个网站项目的自定义cs文件,如图:

    2.CheckRight.cs中的代码如下:

    public class CheckRight : IHttpModule
    {

    public void Dispose()
    {
    }

    public void Init(HttpApplication app)
    {
    app.AcquireRequestState += new EventHandler(app_AcquireRequestState);//nine event
    // app.BeginRequest += new EventHandler(app_BeginRequest);

    void app_AcquireRequestState(object sender, EventArgs e)
    {
    HttpApplication app = sender as HttpApplication;
    if (app.Request.RawUrl.Contains(".aspx"))
    {
    if (app.Session["user"] == null)
    {
    app.Response.Write("<script>alert('请先登录');window.location.href='../Login.htm'</script>");

    //window.location.href='../Login.htm'为当前页赋值为'../Login.htm',使当前页面跳转到Login.htm页面。
    }
    }

    }
    }

    3.web.Config配置一下:

    在<system.web>节点下,配置如下:
    <httpModules>
    <add name="cccccccc" type="CheckRight"/>
    </httpModules>

    其中:name可以任意起,但是type为CheckRight.cs文件中class 的名字,如果有命名空间的话,要在类之前加上命名空间的名字!

  • 相关阅读:
    POJ2828
    Docker容器修改端口映射
    CentOS 7使用ISO镜像配置本地yum源
    Windows 自带的 Linux 子系统
    vue富文本编辑器插件vue-quill-editor使用
    修改docker容器存放位置
    Linux 硬盘相关操作
    centos7基础相关
    ubuntu-k8s搭建
    redhat 6.6 离线docker
  • 原文地址:https://www.cnblogs.com/LpRightNow/p/2868984.html
Copyright © 2011-2022 走看看