具有.asp扩展名的网址的映射路由 [英] Mapping routes for urls with .asp extension
问题描述
我正在尝试创建旧版路由,以将旧的asp链接重定向到新的url.
I am trying to create a legacy route to redirect old asp links to the new urls.
我的路线如下,它是列表中的第一条路线:
My route is as follows and it's the first route in the list:
routes.MapRoute(
"", // Route name
"{*path}", // URL with parameters
new { controller = "Legacey", action = "Legacey" },
new { path = @".*\.asp.*" });// Parameter defaults
我遇到的问题是IIS在它们击中我的路由之前对其进行了拦截并对其进行了404s处理. 我想在web.config中有一个设置可以告诉IIS停止这样做,但我找不到它.
The problem I have is IIS intercepts these and 404s them before they hit my route. I guess there's a setting in the web.config to tell IIS to stop doing this but I can't find it.
推荐答案
You could accomplish this through URL rewriting, as explained in this post
只需将这样的内容添加到您的web.Config中(用ASP页面的重定向URL替换Legacey/Legacey):
Just add something like this to your web.Config (replace Legacey/Legacey with the redirect URL for the asp pages):
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect ASP Files to new URL" stopProcessing="true">
<match url="*\.asp" />
<action type="Redirect" url="Legacey/Legacey" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
我还没有测试过,这只是我从那篇文章中了解到的.
I haven't tested this, it's just what I've understood from that post.
这篇关于具有.asp扩展名的网址的映射路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!