gpt4 book ai didi

asp.net - 使用 HttpModule Asp.net 重定向 URL

转载 作者:行者123 更新时间:2023-12-04 16:54:32 25 4
gpt4 key购买 nike

我创建了一个 HttpModule,这样每当我在浏览器中输入“localhost/blabla.html”时,它都会将我重定向到 www.google.com(这只是一个例子,它实际上是重定向来自手机的请求)

我的问题是:

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

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

3) HttpModule 代码使用 'log4net' 。我是否还需要向 GAC 添加“log4net”?

谢谢

附言该网站使用.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 - 使用 HttpModule Asp.net 重定向 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11633241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com