【发布时间】: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