【问题标题】:Custom HTTP response headers on internal IdentityServer4 endpoints内部 IdentityServer4 端点上的自定义 HTTP 响应标头
【发布时间】:2020-07-03 18:24:02
【问题描述】:

我一直在尝试将一些自定义 HTTP 响应标头添加到内置 IdentityServer 端点,例如 /connect/checksession,使用下面代码 sn-p 中描述的全局过滤方法(取自 Startup.cs ConfigureServices 方法):

services.AddMvc(options =>
{
   options.EnableEndpointRouting = false;
   options.Filters.Add(typeof(SecurityHeadersAttribute));
});

虽然标头在 /AccountSelect/Login 等自定义 MVC 端点上显示得很好,但内部 IdentityServer 端点似乎完全忽略了这些。

我在考虑启动时的注册顺序是否会覆盖全局过滤器。在我的情况下,下面的代码在 AddMvc

之后执行
services.AddIdentityServer(options =>
{
   //code omitted for brevity
});

【问题讨论】:

    标签: authentication asp.net-core-mvc identityserver4


    【解决方案1】:

    一种选择是在请求管道中添加您自己的中间件步骤,该步骤将为您的 IdentityServer 应用程序的每个传入请求执行。

    只需在 Startup.Configure 中添加此代码:

    app.Use(async (context, next) =>
    {
        context.Response.OnStarting(() =>
        {
            context.Response.Headers.Add("MyMagic", "Header");
            return Task.FromResult(0);
        });
        await next();
    });
    

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-24
      • 2019-10-03
      • 2016-05-27
      • 2018-06-08
      相关资源
      最近更新 更多