使用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"); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 为什么ASP.NET身份中的Logout使用POST而不是GET?
- asp.net-mvc – 为什么使用ASP.NET MVC局部视图(.ascx)
- asp.net-mvc – ASP.NET MVC 1和2在Mono 2.4与Fluent NHibe
- asp.net-mvc – 在实体框架代码中为同一表定义多个外键
- asp.net – System.Runtime.InteropServices.COMException功
- asp.net – 每个应用程序池的内存使用
- ASP.NET 打开新页面或页面跳转
- asp.net-mvc-2 – ASP.NET MVC 2和PRG模式
- asp.net – 是否有更好的方法来访问ITemplate中的控件而不是
- ASP.NET Core RC2配置自定义AppSettings