检索 ASP.NET Core 中的 ServerVariables

BDa*_*ley 4 asp.net

我已经实现了 IdentityServer4。该应用程序正在运行 ASP.NET Core。托管环境位于 IIS 上。我正在使用 Shibboleth 对站点执行预身份验证。这会填充 IIS 中的许多服务器变量。(我们不能在我们的环境中使用HTTP headers,一切都必须使用ServerVariables完成)

我想检索服务器变量“AUTH_USER”或“REMOTE_USER”。

在旧版 ASP 或 ASP.NET 中,这就像调用 Request.ServerVariable("AUTH_USER") 一样简单。这在 ASP.NET Core 中发生了变化。

我尝试过 ClaimsPricipal -> User.Identity.Name,(用户名为空,IsAuthenticated 为 false)

我已经确认服务器变量确实已设置。

这个问题与这个问题类似,但没有回答这个问题

yoe*_*alb 8

在Asp.Net Core 3中,有一个GetServerVariable关于HttpContext.

要使用它,您需要安装Microsoft.AspNetCore.Http.ExtensionsNuGet包,实际方法在Microsoft.AspNetCore.Http.HttpContextServerVariableExtensions类中。

注意服务器必须支持,否则会返回null

对于早期版本的 ASP.Net Core,您可以通过调用来使用上下文属性的 features 属性context.Features.Get<IServerVariablesFeature>()