httpHandler-子文件夹问题 [英] httpHandler - subfolder issue

查看:104
本文介绍了httpHandler-子文件夹问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将旧的打字机博客重定向到使用wordpress运行的新博客(永久301重定向).新博客也将在新服务器上.

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.

旧博客具有以下结构: http://subdomain.domain.com/weblog/year/month/what-ever-article.html

the old Blog had the following structure: http://subdomain.domain.com/weblog/year/month/what-ever-article.html

新博客看起来像这样: http://www.domain.com/Blog/index.php/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

我正在使用一个在网上找到的http处理程序,并尝试使用它:

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 

}

要使用此代码,我将处理程序放入web.config

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.

是否有任何方法可以更改脚本或将所有捕获添加到将URL转发到脚本的web.config中?

Is there any way to change my script or add an catch all to the web.config that forwards the URL to my script?

当我使用" http://subdomain.domain .com/weblog/year/month/what-ever-article.html "中的oldURL字符串,那么重定向工作正常……所以我必须将IIS或web.config设置错误.

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.

预先感谢, 帕特里克

推荐答案

我认为您需要为 html 页面添加处理程序,以便它们可以在asp.net下运行

I think that you need to add handlers for the html page, so they can run under the asp.net

您可以使用web.config上的 httpHandlers 来添加html,或者使用iis通过asp.net来处理html或其他文件,并且可以从过滤器中传递.

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.

这篇关于httpHandler-子文件夹问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆