简体   繁体   English

URL重写是否尊重我的ASP .NET MVC路由?

[英]Does URL rewriting respect my ASP .NET MVC routes?

I'm about to normalize all the URLs in my website. 我将规范化我网站中的所有URL。 I'm considering making some rewrite rules, but only if my Html.ActionLink code and my RedirectToAction code will respect those rules. 我正在考虑制定一些重写规则,但Html.ActionLink是我的Html.ActionLink代码和RedirectToAction代码将遵守这些规则。

Will they? 他们会吗? I did some early tests, and it didn't seem to be the case. 我做了一些早期测试,但事实并非如此。

URL rewriting and MVC routing are completely separate processes and they don't know about each other. URL重写和MVC路由是完全独立的过程,它们彼此之间并不了解。

If you create an ActionLink it will look at the routing map you registered in MVC and it will not look at your rewrite rules. 如果创建ActionLink,它将查看您在MVC中注册的路由映射,而不查看您的重写规则。

If you decide to add URL rewriting, you should also define the reverse rules in IIS. 如果决定添加URL重写,则还应该在IIS中定义相反的规则。

Although this might work in theory, in practice I would advise you to just adapt your routing in ASP.NET MVC and not bother with URL rewriting. 尽管从理论上讲这可能可行,但是在实践中我建议您仅在ASP.NET MVC中调整路由,而不必费心URL重写。 The routing system is flexible enough to allow almost any scenario (I haven't encountered situations it couldn't handle). 路由系统足够灵活,几乎可以用于任何情况(我没有遇到过无法解决的情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM