Home > Uncategorized > SEO 301 Redirects for ASP .NET 1.1

SEO 301 Redirects for ASP .NET 1.1

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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: