private string GetRedirect(string badRequest)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"pages/(\d+)$", (System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase));
System.Text.RegularExpressions.MatchCollection matches = regex.Matches(badRequest);
if (matches.Count > 0)
{
string id = matches[0].Value.Replace("pages/", "");
int aId;
try
{
aId = Int32.Parse(id);
return "http://localhost:1731/web/pages/room.aspx?id=" + id;
}
catch
{
}
}
return badRequest;
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string originalUrl = Request.Url.ToString();
string newUrl = GetRedirect(originalUrl);
if (newUrl != originalUrl)
{
System.Uri myUri = new Uri(newUrl);
Context.RewritePath(myUri.PathAndQuery);
}