且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将经典 ASP 请求路由到 .NET - SEO 重定向

更新时间:2022-12-07 08:38:14

@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 才能使状态码起作用.

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:windowsmicrosoft.netframeworkv2.0.50727aspnet_isapi.dll