Archive

Archive for February, 2008

SEO 301 Redirects for ASP .NET 1.1

February 26, 2008 Leave a comment

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:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
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

Advertisements
Categories: Uncategorized