【问题标题】:CORS ISSUE for mvc webapi用于 mvc webapi 的 CORS 问题
【发布时间】:2016-10-26 02:40:38
【问题描述】:

我将 MVC WebApi 托管到 godaddy 服务器,客户端应用程序也托管到服务器,我遇到了问题

XMLHttpRequest 无法加载我的应用程序“Access-Control-Allow-Origin”标头包含多个值“http://xxxxxx.in, *”,但只允许一个值。 Origin 'http://xxxxx.in' 因此不允许访问。

【问题讨论】:

    标签: jquery asp.net-mvc asp.net-web-api2


    【解决方案1】:

    您需要在 Webapi.config 文件中启用 cors

    Webapi.config

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);
            // ...
        }
    }
    
    1. First * (aistrik) - 允许所有来源
    2. 第二个 * (aistrik)- 允许所有标题
    3. 第三个 *(aistrik) - 允许所有方法

    我想这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      我认为这个问题的答案可能会为你提供你所需要的。

      asp.net web api 2 CORS and authentication authorization configuration

      【讨论】:

        猜你喜欢
        • 2023-03-16
        • 2014-12-16
        • 2016-05-14
        • 2016-01-20
        • 2012-08-29
        • 2016-08-12
        • 2014-12-12
        • 2012-09-25
        • 2013-08-04
        相关资源
        最近更新 更多