Unable to rewrite URL to point to a page

Topics: ASP.NET 2.0
Jun 27, 2008 at 8:23 AM
I have a page called Downloads. It can be accessed at http://www.mydomain.com/page/Downloads.aspx. I want to be able to let people access it at http://www.mydomain.com/Downloads.aspx to maintain compatibility with existing links. Unfortunately the code that I wrote to do this in Global.asax doesn't succeed in redirecting the URL:-

void Application_BeginRequest(object sender, EventArgs e)

{

    string path = Request.Url.ToString().ToUpperInvariant();

    if (path.EndsWith("/DOWNLOADS.ASPX") && !path.EndsWith("/PAGE/DOWNLOADS.ASPX"))

        Context.RewritePath("~/page/Downloads.aspx");

}

It gives a 404 because obviously http://www.mydomain.com/page/Downloads.aspx isn't a real address and is itself rewritten somehow.

How can I redirect the request to something that will work with BlogEngine ?

Guy