我有以下路线:
http://somehost/Project/Page/5/Contactgfmsdiojfdui9m
我希望将其永久重定向到:
http://somehost/Project/Page/5/Contact
如何完成我不想支持的错误路由过滤?
答案 0 :(得分:3)
两个选项:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ProjectPageContent_Redirect" stopProcessing="true">
<match url="^/Project/Page/(\d+)/Content.*" />
<action type="Redirect" url="/Project/Page/{R:1}/Content" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
来自Controller的RedirectPermanent
<强> RedirectController.cs 强>
public class RedirectController : Controller
{
public ActionResult ProjectPageContent(Int32 id)
{
return RedirectPermanent(String.Format("/Project/Page/{0}/Content", id));
}
}
<强> RouteConfig.cs 强>
routes.MapRoute(
name: "ProjectPageContent_Redirect",
url: "/Project/Page/{id}/Contact{*extra}",
defaults: new { controller = "Redirect", action = "ProjectPageContent" }
);