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 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET MVC 中的 URL 重定向
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
