简体   繁体   English

asp.net(和mvc)可能会更改代码中的iis重写规则

[英]asp.net (and mvc) possible to alter iis rewrite rules from code

I know this has been asked a number of times, but I haven't see an actual answer yet- using asp.net, and possibly with mvc, is it possible to alter the rewrite rules from the application? 我知道已经问过很多次了,但是我还没有看到实际的答案-使用asp.net,也许使用mvc,是否可以更改应用程序的重写规则?

The normal answer for this is "use mvc routing", but from what I understand, this adds significant overhead for files that would otherwise be considered static - thus, it would be ok to use IIS rewrite for things like css files and images as it will still perform well, but you wouldnt want to serve these static resources up from an mvc/asp.net app as it could create a bottleneck. 正常的答案是“使用mvc路由”,但是据我了解,这增加了文件的开销,这些文件本来就被认为是静态的-因此,可以对诸如CSS文件和图像之类的东西使用IIS重写。仍然可以正常运行,但是您不希望通过mvc / asp.net应用程序提供这些静态资源,因为它可能会造成瓶颈。

Thus: being able to alter the rules for IIS could be a good way to allow a program to create high-performance aliasing, without requiring hand editing of the rules. 因此:能够更改IIS规则可能是允许程序创建高性能别名的好方法,而无需手动编辑规则。

make sense? 说得通?

You could of course modify the Application_BeginRequest of your Global.asax file in ASP.NET(and MVC) to perform URL Rewrites. 您当然可以在ASP.NET(和MVC)中修改Global.asax文件的Application_BeginRequest以执行URL重写。 You could alternatively create a custom HTTP Module to do the URL rewriting, because it gives you the additional flexibility of rearranging it's order in the IIS pipeline. 您也可以创建一个自定义HTTP模块来进行URL重写,因为它为您提供了在IIS管道中重新排列顺序的额外灵活性。

MVC routing works fine for your case as well, since by default IIS uses seperate modules which will process requests for your static content. MVC路由也适用于您的情况,因为默认情况下,IIS使用单独的模块来处理对静态内容的请求。

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

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