在VS2013 MVC4 IIS中向应用程序根目录添加多个级别的虚拟目录

时间:2016-05-03 14:05:40

标签: visual-studio-2013 web-config .net-4.5 iis-express virtual-directory

我正在使用Visual Studion 2013MVC4。我在每个区域使用应用程序和路由规则(RegisterArea覆盖)中的区域。

我的公司决定将我们的网络应用程序升级到现场,现在我必须将Calculator附加到所有javascript脚本,css和跨应用程序的所有其他路径+为所有Controllers执行此操作

我所说的是来自

http://host:1234/legal-services/Wills/Index

http://host:1234/legal-services/Calculator/Wills/Index

所以在替换了所有脚本之后我转到csproj并为应用程序root添加了覆盖,因此它会覆盖所有控制器,但这完全被忽略了。

enter image description here

我假设当覆盖主机时只能使用主机名和端口但不能使用文件夹。

更新 我还尝试直接修改.csproj文件以更改IISUrl设置


<IISUrl>http://localhost:50766/legal-services/</IISUrl>

<IISUrl>http://localhost:50766/legal-services/Calculator/</IISUrl>

但这对以太没有影响。

UPDATE2:

因此applicationHost.config中的C:\Users\[username]\Documents\IISExpress\config中的配置发生了更改,以添加其他虚拟目录

来自

    <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
    <virtualDirectory path="/legal-services" physicalPath="C:\hg\Website" />

    <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
    <virtualDirectory path="/legal-services/calculator" physicalPath="C:\hg\Website" />

然而现在我遇到了不同的问题,因为我现在正在处理虚拟目录上的多个层,我得到403并且它非常有意义,因为中间的路径(/legal-services)不在列表中。

当我添加

 <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
<virtualDirectory path="/legal-services/calculator" physicalPath="C:\hg\Website" />
<virtualDirectory path="/legal-services" physicalPath="C:\hg\Website" />

我遇到配置错误(我假设因为所有3条路径都指向同一目录)

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

<authentication mode="Forms">

表示路径未标识为Web应用程序或存在web.config冲突。

如何配置这个以便将path =“/ legal-services / calculator”标识为没有web.config冲突的应用程序?

1 个答案:

答案 0 :(得分:0)

所以解决方案是在applicationHost.config中创建两个单独的应用程序路径,如下所示,其中主路径具有虚拟目录路径的一部分,第二个应用程序具有完整的虚拟目录路径,如下所示:

<site name="Website-Site" id="2">
     <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\hg\Website" />
        <virtualDirectory path="/legal-services" physicalPath="C:\hg\" />
    </application> 
    <application path="/legal-services/Calculator" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\hg\Website" />
    </application>              
    <bindings>
        <binding protocol="http" bindingInformation="*:50766:localhost" />
    </bindings>
</site>

希望这可以节省你一些时间。