httpHandler - 子文件夹问题
我正在尝试将我的旧打字板博客重定向到使用 WordPress 运行的新博客(永久 301 重定向)。新博客也将位于新服务器上。
旧博客的结构如下: http://subdomain.domain.com/weblog/year/ Month/what-ever-article.html
新博客如下所示: http://www.domain.com/ Blog/index.php/year/month/what-ever-article.html
我正在使用我在网上找到的 http 处理程序并尝试使用它:
public class MyHttpModule :IHttpModule
{
public MyHttpModule()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
string oldURL = System.Web.HttpContext.Current.Request.Url.ToString();
string newURL = String.Empty;
//oldURL =
if (oldURL.ToString().ToLower().IndexOf("articles") >= 0 || System.Web.HttpContext.Current.Request.Url.ToString().ToLower().IndexOf("weblog") >= 0)
{
newURL = oldURL.Replace("subdomain.domain.com/weblog", "www.domain.com/Blog/index.php");
if (newURL.ToLower().Contains("subdomain"))
{
newURL = "http://www.domain.com/Blog";
}
}
else
{
newURL = "http://www.domain.com/Blog";
}
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.StatusCode = 301;
System.Web.HttpContext.Current.Response.AddHeader("Location", newURL);
System.Web.HttpContext.Current.Response.End();
}
#endregion
}
要使用此代码,我将处理程序放入web.config
<httpModules>
<add name="MyHttpModule" type="MyHttpModule, App_Code"/>
</httpModules>
我遇到的问题是,当我想从 http://subdomain.domain.com/weblog/year/month/what-ever-article.html,我收到一个错误,该文件夹不存在。
有什么方法可以更改我的脚本或将所有内容添加到 web.config 以将 URL 转发到我的脚本吗?
当我使用“http://subdomain.domain.com/ weblog/year/month/what-ever-article.html” in oldURL 字符串,然后重定向工作得很好...所以我一定有一些 IIS 或 web.config 设置错误。
提前致谢, 帕特里克
I am trying to redirect my old typepad blog to my new blog (permanent 301 redirect) that runs with wordpress. The new blog will also be on a new server.
the old Blog had the following structure:
http://subdomain.domain.com/weblog/year/month/what-ever-article.html
The new Blog looks like this:
http://www.domain.com/Blog/index.php/year/month/what-ever-article.html
I am using an http handler that I found online and tried to work with it:
public class MyHttpModule :IHttpModule
{
public MyHttpModule()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
string oldURL = System.Web.HttpContext.Current.Request.Url.ToString();
string newURL = String.Empty;
//oldURL =
if (oldURL.ToString().ToLower().IndexOf("articles") >= 0 || System.Web.HttpContext.Current.Request.Url.ToString().ToLower().IndexOf("weblog") >= 0)
{
newURL = oldURL.Replace("subdomain.domain.com/weblog", "www.domain.com/Blog/index.php");
if (newURL.ToLower().Contains("subdomain"))
{
newURL = "http://www.domain.com/Blog";
}
}
else
{
newURL = "http://www.domain.com/Blog";
}
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.StatusCode = 301;
System.Web.HttpContext.Current.Response.AddHeader("Location", newURL);
System.Web.HttpContext.Current.Response.End();
}
#endregion
}
To use this code, I put the handler into the web.config
<httpModules>
<add name="MyHttpModule" type="MyHttpModule, App_Code"/>
</httpModules>
The issue that I have is that when I want to redirect from the http://subdomain.domain.com/weblog/year/month/what-ever-article.html, I get an error that the folder would not exist.
Is there any way to change my script or add an catch all to the web.config that forwards the URL to my script?
When I use "http://subdomain.domain.com/weblog/year/month/what-ever-article.html" in oldURL string, then the redirect works just fine... so I must have some IIS or web.config settings wrong.
Thanks in advance,
Patrick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要为html页面添加处理程序,以便它们可以在asp.net下运行
您可以使用web.config上的httpHandlers来添加html,或iis通过asp.net处理您的html或其他文件,并且可以从您的过滤器传递。
I think that you need to add handlers for the html page, so they can run under the asp.net
You can use the httpHandlers on web.config to add the html, or iis to handle your html or other files via the asp.net and can pass from your filter.