httpHandler - subfolder issue

感情迁移 提交于 2019-12-11 23:26:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2715352/httphandler-subfolder-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!