ori*_*hen 5 asp.net url redirect
我创建了一个HttpModule,以便每当我在浏览器中输入"localhost/blabla.html"时,它会将我重定向到www.google.com(这只是一个例子,它真的是重定向来自手机的请求)
我的问题是:
1)如何告诉IIS(7.0)将每个请求重定向到"HttpModule",以便它独立于网站.我可以更改web.config,但就是这样.
2)我是否需要将.dll添加到GAC?如果是这样,我该怎么做?
3)HttpModule代码使用'log4net'.我是否还需要将"log4net"添加到GAC?
谢谢
PS该网站正在使用.net 2.0.
Gov*_*iya 12
您可以在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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12521 次 |
| 最近记录: |