Я нашел решение. Это очень легко с помощью HttpModule. Пожалуйста, посмотрите на мой следующий пример кода.
В глобальном web.config
<configuration>
<system.web>
<httpModules>
<add name="RedirectModule" type="MySolution.RedirectModule, MySolution" />
</httpModules>
</system.web>
<!-- The following code will be used by IIS 7+ -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="RedirectModule" />
<add name="RedirectModule" type="MySolution.RedirectModule MySolution" />
</modules>
</system.webServer>
</configuration>
В MySolution / RedirectModule.cs
using System;
using System.Web;
namespace MySolution
{
public class RedirectModule : IHttpModule
{
#region IHttpModule Members
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(HttpApplication_BeginRequest);
}
public void Dispose() {}
#endregion
void HttpApplication_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
if (*[logic for checking before redirect]*)
{
app.Response.Redirect(*[url]*);
}
}
}
}
Для получения дополнительной информации, пожалуйста, посмотрите исходный код Url Mapping как UrlRewritingNet.UrlRewrite .
PS. IHttpModule - очень мощный интерфейс. Он может справиться с каждым типом запроса. Таким образом, это может помочь мне полностью решить этот вопрос.