代码之家  ›  专栏  ›  技术社区  ›  moueidat

ASP NET MVC-403禁止访问被拒绝

  •  0
  • moueidat  · 技术社区  · 7 年前

    在团队项目中,ASP.NET Web API MVC的使用仅仅是因为WSFederation协议,它承载了一个角度构建。 该项目有一个自定义的委托处理程序,它用来调用我们的后端(AngularWeb不直接调用API URL,它调用“本身”,这样委托处理程序就可以调用我们的后端)

    整个构建部署在一个Azure AppService中,工作正常:)(将显示wsfed提供程序接口,并且在身份验证之后,AngularWebapp也将显示)。

    enter image description here

    但有时我会遇到一个“漂亮的”“403-禁止访问被拒绝”,这似乎与后端无关(没有在应用程序洞察中登录)。似乎如果我清理缓存和/或cookie,它会再次工作……但是在prod环境中,他们有时会遇到这个问题,这有点尴尬:s

    有什么问题吗?那么,在web.config中添加什么使其更具说服力:p?

    以下是我的web.config示例(我省略了一些与角度路线或应用程序设置相关的代码):

    web.config:

    <system.web>
        <compilation debug="true" targetFramework="4.6.2" />
        <httpRuntime targetFramework="4.6.2" />
        <httpModules>
            <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
        </httpModules>
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>
    
    <location path="FederationMetadata">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <clear />
                <add name="X-XSS-Protection" value="1; mode=block" />
                <remove name="X-Powered-By" />
            </customHeaders>
        </httpProtocol>
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <remove name="OPTIONSVerbHandler" />
            <remove name="TRACEVerbHandler" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true">
            <remove name="ApplicationInsightsWebTracking" />
            <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
            <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
            <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
        </modules>
        <staticContent>
          <clientCache cacheControlMode="DisableCache" />
          <remove fileExtension=".woff" />
          <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
          <remove fileExtension=".json" />
          <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
    </system.webServer>
    

    在视图文件夹中还有一个web.config,但我没有触摸它(它是默认生成的)。

    1 回复  |  直到 7 年前
        1
  •  0
  •   moueidat    7 年前

    我终于发现自己为什么会有这个问题 =>对于可能处于相同情况的人,是在Azure中定义的WAF规则(World Application Firewall)导致403被禁止