【问题标题】:Issue authenticating Web api from MVC app从 MVC 应用程序发出身份验证 Web api
【发布时间】:2016-06-07 15:26:16
【问题描述】:

我在不同的服务器上托管了 MVC 应用程序和 Web Api。但是如果从我的 mvc web 应用程序访问,我无法使用 ADFS 验证我的 web api。

获取“CORS 错误”

提前致谢

【问题讨论】:

    标签: c# owin claims-based-identity adfs3.0


    【解决方案1】:

    您需要添加 Nuget 包 Microsoft.ASP.Net.Cors 并将 [EnableCors("", "", "*")] 属性添加到您的控制器类

    [EnableCors("*", "*", "*")]
    public class YourController : ApiController
    { 
    }
    

    在 WebApiConfig.cs 中添加这个

    public static void Register(HttpConfiguration config)
      {
        config.EnableCors();
      }
    

    您可以查看Link

    【讨论】:

      【解决方案2】:

      请不要添加带有“*”的 CORS 过滤器(通配符允许任何 IP/域..)。

      Owasp 的备忘单有一些方便的提示和更多信息:https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet#Cross_Origin_Resource_Sharing

      【讨论】:

        猜你喜欢
        • 2017-10-29
        • 2017-03-03
        • 2015-09-05
        • 2016-07-03
        • 2014-04-26
        • 1970-01-01
        • 2018-10-09
        • 2015-09-17
        • 2014-01-26
        相关资源
        最近更新 更多