使用.asp扩展来映射URL的路由 [英] Mapping routes for urls with .asp extention
问题描述
我正在尝试创建遗留路线,将旧的asp链接重定向到新的网址。
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.
推荐答案
您可以通过URL重写来完成此操作,如这篇文章
You could accomplish this through URL rewriting, as explained in this post
只需将这样的内容添加到您的web.Config中(将Legacey / Legacey替换为asp页面的重定向URL):
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扩展来映射URL的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!