在global.asax.cs重定向路由

Gui*_*sta 2 .net routes asp.net-mvc-3

有没有办法让我通过使用内部规则localhost/subscribe将每个访问权限重定向到或者我应该从操作重定向?localhost/subscribe.aspxglobal.asax.cs

Vit*_*liy 9

以下代码应该适合您:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (Request.RawUrl.ToLower().EndsWith("subscribe")) 
    {
        Response.Redirect("subscribe.aspx");
    }
}
Run Code Online (Sandbox Code Playgroud)

或者在Application_PreRequestHandlerExecute方法内部,如果您还要使用Session进行验证