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 的名字,如果有命名空间的话,要在类之前加上命名空间的名字!

  • 相关阅读:
    九、Shell 流程控制
    八、Shell test 命令
    七、Shell printf 命令
    六、Shell echo命令
    五、Shell 基本运算符
    四、Shell 数组
    三、Shell 传递参数
    二、Shell 变量
    一、Shell 教程
    KVM 介绍(1):简介及安装
  • 原文地址:https://www.cnblogs.com/LpRightNow/p/2868984.html
Copyright © 2011-2022 走看看