HttpModule(URL重写).html伪静态

HttpModule(URL重写 ).html伪静态

利用HttpAplication中的-->
1.BeginRequest(在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生)

来执行RewritePath

简单URL重写实例代码

public class IIHttpMoudle:IHttpModule
    {

        #region IHttpModule Members

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        //初始化事件 
        public void Init(HttpApplication context)
        {
            //将方法注册到事件上面
            context.BeginRequest += MyHttpModult;
        }

        void MyHttpModult(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            string filepath = app.Context.Request.Path;
            string filename = System.IO.Path.GetFileName(filepath);
            Regex reg = new Regex("View.(\\d+)html");//正则表达式规则
            Match match = reg.Match(filename);
            if (match.Success)
            {
                string id = match.Groups[1].Value;//得到id
                app.Context.RewritePath("View.aspx?id=" + id);
            }
        }
        #endregion
    }





一个完整的HTTP请求在ASP.NET Framework的处理过程如下:

HttpRequest ——> inetinfo.exe ——> ASPNET_ISAPI.dll ——> Http Pipeline ——> ASPNET_WP.exe ——> HttpRuntime ——> HttpApplication Factory  ——> HttpApplication  ——> HttpModule ——> HttpHandler Factory  ——> HttpHandler  ——> HttpHandler.ProcessRequest()

HTTP Handler提供了类似于ISAPI Server Extention的功能,而HttpModule实现了类似于ISAPI Filter的功能。使用自定义的Handler会覆盖系统默认的Handler,而Module是可以多个同时存在的。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值