I need to move all requests from one domain to another. I want to change part of URL, like subdomain.olddomain/url -> subdomain.newdomain/url.
I was sure that this is piece of cake and wrote Application_Begin request as:
void Application_BeginRequest(object sender, EventArgs e)
{
string url = Request.Url.ToString().ToLower();
string from = ConfigurationSettings.AppSettings["from"];
if (url.IndexOf(from) >= 0)
{
url = url.Replace(from, ConfigurationSettings.AppSettings["to"]);
Response.Redirect(url);
}
else
{
if (url.IndexOf("error.aspx") < 0)
{
Response.Redirect("Error.aspx?url=" + Server.UrlEncode(url));
}
}
}
So far, I forget, that BeginRequest started only when file physically exist.
Any ideas, how I can make such redirect in asp.net without creating hundreds of old pages?