Dec 20, 2011 at 5:16 AM
Edited Dec 20, 2011 at 7:18 AM
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)
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);