Simple 301 Redirects ASP.NET 4.0 in Code

Sometimes it is just easier to code in 301 redirects into an application that you are building. Specially if it is replacing a system on the same domain.

I had this recently with

It is very easy to use your Global.asax file to program in 301 redirects without having to use IIS when using ASP.NET 4.0.

void Application_BeginRequest(object sender, EventArgs e)


        // old quoteline system 301 redirects

        string localUrl = Request.Url.LocalPath;

        ArrayList redirectUrls = new ArrayList();





        foreach (string url in redirectUrls)


            if (localUrl.IndexOf(url, StringComparison.OrdinalIgnoreCase) >= 0)






If you have more complex URLs that contain query string data that must be maintained @improvedk has a fairly good article about that… review the resource link.



Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

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

You are commenting using your 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