URL Redirection in ASP.NET MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-04 11:35:54

You could use the URL Rewrite module in IIS. It's as simple as putting the following rule in your <system.webServer> section:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Login page redirect" stopProcessing="true">  
                <match url="login.aspx" />  
                <action type="Redirect" redirectType="Permanent" url="account/login" />  
            </rule>  
        </rules>
    </rewrite>

    ...
</system.webServer>

The module is very powerful and allows you any kind of rewrites and redirects. Here are some other sample rules.

in the global.asax

void Application_BeginRequest(Object source, EventArgs e)
    {
        //HttpApplication app = (HttpApplication)source;
        //HttpContext context = app.Context;

        string reqURL = HttpContext.Current.Request.Url;

        if(String.compare(reqURL, "www.website.com/login.aspx")==0)
        {
            Response.Redirect("www.website.com/account/login");
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!