zoukankan      html  css  js  c++  java
  • HttpModule Url 重写

    1.新建MyModule去实现IHttpModule接口

        //当前请求的应用程序的对象的变量
    private HttpApplication _application;

    //初始化事件
    public void Init(HttpApplication context)
    {
    _application = context;
    //加载context执行的事件context_BeginRequest
    context.BeginRequest+=new EventHandler(context_BeginRequest);
    }
    void context_BeginRequest(object sender, EventArgs e)
    {
    //在此对请求的Url重写

    //要定义到的路径
    string path = "admin/index.aspx";

    //获取被请求的路径
    string requstPath = _application.Context.Request.RawUrl;

    string[] list = requstPath.Split(Convert.ToChar("/"));
    if(list[list.Length-1]=="index.aspx")
    {
    _application.Context.RewritePath(path);
    }

    }

    2.配置文件,定义全局应用该MyModeule

            <httpModules>
    <add name="MyModule" type="MyModule,App_Code"/>
    </httpModules>

    主要用于隐藏URL地址或者是伪装URL
     

  • 相关阅读:
    文件
    模块
    异常
    抽象
    条件,循环
    centos6.4 64位下安装nfs文件共享系统
    YUM安装删除软件
    apache常用的两种工作模式 prefork和worker
    shell不打印
    APACHE安装配置说明
  • 原文地址:https://www.cnblogs.com/xyangs/p/2381237.html
Copyright © 2011-2022 走看看