【问题标题】:Can I change web.config settings separately for different routes in ASP.NET MVC3?我可以为 ASP.NET MVC3 中的不同路由分别更改 web.config 设置吗?
【发布时间】:2013-05-28 05:28:24
【问题描述】:
我有一个 ASP.NET MVC3 应用程序,其中路由的配置方式是,对/UsersRequests 的所有请求都由一个控制器提供服务,而对/ServiceRequests 的所有请求都由另一个控制器提供服务,处理方式略有不同。
现在我需要更改在 web.config 中配置的 <system.webServer><security><access sslFlags> 属性。如果我在根级别执行此操作,它会产生一些不良影响,因此我只想将其更改为 /ServiceRequests 路径。
这种改变只能针对一条路线吗?
【问题讨论】:
标签:
asp.net
.net
asp.net-mvc
asp.net-mvc-3
iis
【解决方案1】:
这可以使用<location> 元素来实现:
<?xml version="1.0"?>
<configuration>
<!-- other sections here -->
<location path="ServiceRequests">
<system.webServer>
<security>
<!-- here goes the value that is changed for
this location only
-->
<access sslFlags="SslNegotiateCert"/>
</security>
</system.webServer>
</location>
<system.webServer>
<!-- all the usual stuff goes here and only the stuff
mentioned under "location" above will be overriden
by values specified in there
-->
</system.WebServer>
</configuration>