重定向URL使用HTTP模块Asp.net [英] Redirect URL Using HttpModule Asp.net

查看:119
本文介绍了重定向URL使用HTTP模块Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个HttpModule,这样每当我在浏览器中输入本地主机/ blabla.html,它将我重定向到www.google.com(这只是一个例子,它是真正重定向从手机来请求)

I have created an HttpModule so that Whenever I type "localhost/blabla.html" in the browser, it will redirect me to www.google.com (this is just an example, it's really to redirect requests coming from mobile phones)

我的问题是:

1)我怎么知道IIS(7.0)重定向每个请求的HTTP模块,因此,它是独立的网站。我可以改变的web.config但仅此而已。

1) How do I tell IIS(7.0) to redirect each request to the "HttpModule" so that it is independent of the website. I can change the web.config but that's it.

2)我是否需要.dll文件添加到GAC?如果是这样,我该怎么办呢?

2) Do I need to add the .dll to the GAC? If so, How can I do that?

3)的HttpModule code使用'log4net的。我需要'log4net的添加到GAC呢?

3) The HttpModule code uses 'log4net' . do I need to add 'log4net' to the GAC as well?

感谢

P.S。该网站是使用.NET 2.0。

P.S. the site is using .net 2.0.

推荐答案

您可以使用请求对象的BeginRequest事件

You can use request object in BeginRequest event

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");
          }
    }

}

这篇关于重定向URL使用HTTP模块Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆