URL Re-direction

Dec 20, 2011 at 5:16 AM
Edited Dec 20, 2011 at 7:18 AM

Hi All!

I have a blog for displaying profiles of people. The title of the Blogs is the name of the people like John, Paul and Ringo.

I would like a friendly URL like "www.URL.com/john" instead of "www.URL/post/john.aspx".

Is there a way to catch the HTTP 404 error and then write code to extract the name out of "www.URL.com/name" and then re-direct the post to "www.URL/post/name.aspx" ?

I added this code to error404.aspx.cs and I still get the HTTP Error 404:

    protected void Page_Init(object sender, EventArgs e)
        #region Gerardo
        if (Request.Url.ToString().LastIndexOf("/") > 0 && !Request.Url.ToString().EndsWith(".aspx"))
            string newURL = Request.Url.ToString().Substring(Request.Url.ToString().LastIndexOf("/") + 1);
            this.Response.Redirect("~/post/" + newURL + ".aspx", true);


Dec 20, 2011 at 3:10 PM

I got it to work by modifying the web.config to use my ISP's recommended code:

<httpErrors errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx" responseMode="ExecuteURL"



Dec 20, 2011 at 3:13 PM

This is much more involved than that. Take a look at this thread for example.