【问题标题】:Azure websites doesnt allow to send custom headers?Azure 网站不允许发送自定义标头?
【发布时间】:2016-03-26 11:42:43
【问题描述】:

为什么 azure 网站会忽略我的 Web 应用程序自定义标头? 我尝试通过 3 种方法发送标头:

我尝试安装 Cors nuget 包:

    public static void Register(HttpConfiguration config)
    {
        config.EnableCors(new EnableCorsAttribute("*", "*", "*");
    }

还尝试在 web.config 中设置自定义标头

<system.webServer>
 <httpProtocol>
   <customHeaders>
     <add name="Access-Control-Allow-Origin" value="*" />
   </customHeaders>
 </httpProtocol>
</system.webServer>

最后我尝试创建过滤器:

public class CorsFilter : ActionFilterAttribute
{
    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
    }
}

以上三种方法都在我的本地开发环境中运行良好。但是当我将我的应用程序发布到 azurewebistes 时,它会忽略我的自定义标头。有什么理由吗?

我订阅了 Dreamspark。

【问题讨论】:

    标签: asp.net asp.net-mvc azure dreamspark


    【解决方案1】:

    您是否尝试过通过门户设置 CORS 策略?

    https://portal.azure.com >> YourAppService >> 设置 >> CORS

    【讨论】:

    • 我尝试在 azure web app 中添加自定义响应头,一些特定的 header 在 azure web app 中没有生效。我很沮丧
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多