ASP.NET MVC中的URL重定向 [英] URL Redirection in ASP.NET MVC

查看:187
本文介绍了ASP.NET MVC中的URL重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个网站上工作,该网站以前是用ASP.NET Web窗体构建的,现在是用ASP.NET MVC构建的.

I was working on a Website which was earlier built with ASP.NET Web Forms and now is built with ASP.NET MVC.

我们上周发布了新的MVC版本.

We made the new MVC version live last week.

但是旧的登录URL为 www.website.com/login.aspx 却已被许多用户标记为书签,他们仍在使用该URL,因此会出现404错误

But the old login url which is www.website.com/login.aspx has been bookmarked by many users and they still use that and hence they get 404 errors.

因此,我想知道哪种方法是将用户从旧url重定向到新的mvc url的最简单和最佳方法,而新的mvc url是 www.website.com/account/login

So I was wondering which would be the easiest and best way to redirect the user from the old url to the new mvc url which is www.website.com/account/login

像此登录URL一样,我希望用户也可以为其他几个URL加书签,那么处理此问题的最佳方法是什么?

Like this login url, I am expecting the users may have bookmarked few other urls also, so what will be the best way to handle this ?

推荐答案

您可以使用 URL Rewrite module 在IIS中.只需在您的<system.webServer>部分中放置以下规则即可:

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>

该模块非常强大,允许您进行任何类型的重写和重定向.这是其他 sample rules .

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

这篇关于ASP.NET MVC中的URL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆