ActionFilterAttribute .net核心WebApi。设置自定义响应标头

时间:2017-09-24 13:43:15

标签: asp.net-core-webapi asp.net-core-2.0

尝试varios方法,而不是成功。 我想更改标题并在javascript中获取

enter image description here

结果debug,headers.Add 标题未知=我的标题授权

enter image description here

我无法在javascript中获取它,因为他没有发送标头,如何发送标头?

.net core web api 2.0

1 个答案:

答案 0 :(得分:0)

解决!

solved! // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseMiddleware(typeof(ErrorHandlingMiddleware));
        app.UseCors(b => b.AllowAnyHeader().WithExposedHeaders("Authorization").AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
        app.UseMvc();

    }

添加.WithExposedHeaders(“授权”)

THX