Feb
26
SEO 301 Redirects for ASP .NET 1.1
Filed Under (Web Development) by manatarms on 26-02-2008
Tagged Under : .NET, ASP
I recently worked on a project where any URL following the form of http://www.mydomain.com/subDomain/Default.aspx needed to 301 redirect to http://www.mydomain.com/subDomain/. Basically this calls for stripping the ‘Default.aspx’ off of any request that has it. The project was to be completed using Visual Basic .NET 1.1.
The solution is is to add a few lines of code in the Global.asax.vb file inside of the Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) function. The final product looks like this:
1 2 3 4 5 6 7 8 9 | Sub Application_BeginRequest(ByVal sender As Object, ByVal e AsEventArgs) Dim oPath As String = Request.CurrentExecutionFilePath.ToLower If Not oPath.EndsWith("default.aspx") Then Return Response.Status = "301 Moved Permanently" Response.AddHeader("Location", "http://www.myDomain.com" + oPath.Substring(0, oPath.IndexOf("default.aspx"))) End Sub |