URL Redirection in ASP.NET MVC(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.
但是旧的登录网址 www.website.com/login.aspx 已被许多用户添加为书签,他们仍在使用该网址,因此他们收到 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 的最简单和最好的方法是 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模块
在 IIS 中.就像将以下规则放在
部分一样简单:
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
.
这篇关于ASP.NET MVC 中的 URL 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!