加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

使用HttpModule Asp.net重定向URL

发布时间:2020-12-15 19:52:20 所属栏目:asp.Net 来源:网络整理
导读:我创建了一个HttpModule,以便每当我在浏览器中输入“localhost / blabla.html”时,它会将我重定向到www.google.com(这只是一个例子,它真的是重定向来自手机的请求) 我的问题是: 1)如何告诉IIS(7.0)将每个请求重定向到“HttpModule”,以便它独立于网站.我可
我创建了一个HttpModule,以便每当我在浏览器中输入“localhost / blabla.html”时,它会将我重定向到www.google.com(这只是一个例子,它真的是重定向来自手机的请求)

我的问题是:

1)如何告诉IIS(7.0)将每个请求重定向到“HttpModule”,以便它独立于网站.我可以更改web.config,但就是这样.

2)我是否需要将.dll添加到GAC?如果是这样,我该怎么做?

3)HttpModule代码使用’log4net’.我是否还需要将“log4net”添加到GAC?

谢谢

附:该网站正在使用.net 2.0.

解决方法

您可以在BeginRequest事件中使用请求对象
public class MyHttpModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
          context.BeginRequest += new EventHandler(this.context_BeginRequest);
    }

    private void context_BeginRequest(object sender,EventArgs e)
    {
          HttpApplication application = (HttpApplication)sender;
          HttpContext context = application.Context;

          //check here context.Request for using request object 
          if(context.Request.FilePath.Contains("blahblah.html"))
          {
               context.Response.Redirect("http://www.google.com");
          }
    }

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读