【发布时间】:2012-09-11 09:47:04
【问题描述】:
我在 www.mydomain.com 有我的网站 asp 网页,而博客位于 www.mydomain.com/blog 内。我不得不将博客移动到一个子域,所以我需要编写一个模块来将博客中任何页面的任何调用重定向到新的子域。
它在我的机器上工作,但当我上传到共享主机时却不行。有什么想法有什么问题吗?
我写了以下代码
public void ProcessRequest(HttpContext context)
{
string sourceUrl = @"www.mydomain.com/blog";// @"localhost:51393/blog"
string destinationUrl = @"blog.mydomain.com/blog";
string currentLocation = context.Request.Url.AbsoluteUri;
if(currentLocation.ToLower().Contains(sourceUrl))
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.StatusCode = 301;
System.Web.HttpContext.Current.Response.AddHeader("Location", currentLocation.Replace(sourceUrl, destinationUrl));
System.Web.HttpContext.Current.Response.End();
}
}
并添加了这些处理程序
<httpHandlers>
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" path="*" type="MyHandler,App_Code.dll"/>
非常感谢任何帮助。
我知道它与httpHandler - subfolder issue 非常相似,但它不起作用。
【问题讨论】:
标签: c# asp.net httphandler