路由经典ASP请求.NET - SEO重定向 [英] Routing Classic ASP Requests To .NET - SEO Redirects
问题描述
我们正在与.NET 3.5的解决方案替换旧的传统的ASP网站。
We are replacing an old classic asp website with a .NET 3.5 solution.
我们需要重定向所有的经典ASP请求到aspx页面(即contactus.asp,现在可以路线/contact-us/default.aspx)。我喜欢woudl对于要求打Global.asax的,所以我可以做这样的事情。
We need to redirect all of the classic ASP requests to aspx pages (i.e. contactus.asp, may now route to /contact-us/default.aspx). What I woudl like is for the requests to hit global.asax so I can do something like
If url == "bob.asp"
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", SiteConfig.SiteURL + redirectUrl);
End If
有两种不雅的解决方案。
There are two inelegant solutions.
A)将一个global.asa文件,并通过做路由。
A) Place a global.asa file and do the routing through that.
B)地图ASP文件到.NET引擎。太好了,但随后如果我们需要托管在我们的网站IIS将发送请求到错误的地方。传统的ASP网站
B) Map asp files to the .NET engine. Great, but then if we need to host classic asp sites on our sites IIS will be sending the requests to the wrong place.
我找到了一个很好的解决方案在这里
I found a nice solution here
http://forums.asp.net/p/1202225/3458901.aspx
其中指出这样的事情可能工作...
Which stated something like this may work...
<buildProviders>
<add extension=".php" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
<httpHandlers>
<add verb="*" path="*.php" type="System.Web.UI.PageHandlerFactory" validate="True" />
</httpHandlers>
这例子是用于PHP但我相信同样的事情会为ASP工作。然而后更改的.php在本例中为.asp,并把这些标签,我有没有快乐(500服务器错误实际上)web.config中正确的部分。
This example was for php but I assume the same thing would work for asp. However after changing .php to .asp in the example and placing the tags in the correct part of the web.config I'm having no joy (a 500 server error actually).
任何人都可以揭示出这个任何灯光或给我一个完美的解决方案。
Can anyone shed any light on this or give me an elegant solution.
有一种感觉,将上述溶液难道不为PHP或ASP作为工作IIS将路由请求它获取到.NET引擎之前。
Had a feeling the above solution wouldnt work for php or asp as IIS will have routed the request before it gets to the .NET engine.
在此先感谢
史蒂夫
推荐答案
大编辑:我指出通过@EdSF的意见,答案是错的。在怀疑我检查使用Firebug,并且,实际上,这是错误
Big edit: I was pointed by @EdSF in the comments that the answer was wrong. In disbelief I checked using Firebug, and, in fact, it was wrong.
您需要使用 Context.Response.RedirectLocation
的状态code工作。
You need to use Context.Response.RedirectLocation
for the status code to work.
我在做同样的在Global.asax中:
I'm doing the same in global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
Dim fullOriginalpath As String = Request.Url.ToString.ToLower
If (fullOriginalpath.Contains("/verarticulo.asp?articuloid=")) Then
Context.Response.StatusCode = 301
''// this does not work, returns a 302
''//Context.Response.Redirect("/noticias/" + getIDFromPath(fullOriginalpath))
''// this does right way
Context.Response.RedirectLocation = "/noticias/" + getIDFromPath(fullOriginalpath)
Context.Response.End()
ElseIf (fullOriginalpath.Contains("/archivo.asp")) Then
Context.Response.StatusCode = 301
Context.Response.RedirectLocation = "/archivo/"
Context.Response.End()
ElseIf (fullOriginalpath.EndsWith("/default.asp")) Then
Context.Response.StatusCode = 301
Context.Response.RedirectLocation = "/"
Context.Response.End()
End If
End Sub
你所要做的,如果你使用的是II6的唯一的事情,你必须配置该ISAPI筛选器
是这样的:
The only thing you have to do if you are using II6 you have to configure this ISAPI filter in this way:
该文件是 C:\\ WINDOWS \\ microsoft.net \\框架\\ V2.0.50727 \\ ASPNET_ISAPI.DLL
这篇关于路由经典ASP请求.NET - SEO重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!