繁体   English   中英

在 web.config 中设置位置路径会导致 404(IIS、ASP.NET Core)

[英]Setting location path in web.config results in 404 (IIS, ASP.NET Core)

我们正在从 ASP.Net 迁移到 ASP.Net Core。

我们需要为不同的路径配置不同的认证

<location path="controllerpath/method">
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
</location>

但是,一旦我们添加<location path="xyz">条目,指定的路径就不再可达,并且调用者得到 404 错误。 即使只是放

<location path="xyz/abc">
</location>

足以触发404响应。 如果我删除此条目,则可以再次访问。 404 直接来自 IIS,因为即使应用程序无法启动(例如,所有其他调用都会导致 503),通过位置路径指定的路径仍然会导致 404。

这是完整的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <remove name="aspNetCore"/>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified"/>
      </handlers>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="52428800"/>
        </requestFiltering>
        <authorization>
          <add accessType="Allow" users="*" verbs="OPTIONS"/>
        </authorization>
      </security>
      <aspNetCore processPath="dotnet" arguments=".\assembly.dll" hostingModel="inprocess"> 
         <handlerSettings>
        <handlerSetting name="debugLevel" value="file" />
        <handlerSetting name="debugFile" value="c:\temp\ancm.log" />
     </handlerSettings>
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>
      </aspNetCore>
      <httpProtocol allowKeepAlive="false">
        <customHeaders>
          <remove name="X-Powered-By"/>
        </customHeaders>
      </httpProtocol>
          <directoryBrowse enabled="true"/>
          <httpCompression>
            <dynamicTypes>
              <remove mimeType="*/*"/>
              <add mimeType="*/*" enabled="true"/>
            </dynamicTypes>
          </httpCompression>
        </system.webServer>
      </location>  
        <location path="xyz/abc" allowOverride="true">        
        </location>
    </configuration>
    <!--ProjectGuid: 29529648-A3F4-44CB-827B-B6B81B00A09C-->

我找到了解决方案:

属性inheritInChildApplications="false"使得处理程序没有为其他路径注册。 删除属性(或将值更改为 true)后,一切都按预期工作。 我猜 IIS 然后试图将路径定位为资源。

暂无
暂无

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

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