Search code examples
authenticationiis.net-coreserver-variables

How to access serverVariable like AUTH_USER in Dot net core


In standard framework, we can context.user.Request.ServerVariables.Get("AUTH_USER");but how to access similar variable in dot net core


Solution

  • You need to use Features, it seems you need IServerVariablesFeature

    Your code will look like this:

    var svf = httpContext.Features.Get<IServerVariablesFeature>();
    var authUser = svf == null ? "No feature :( Do you have IIS?" : svf["AUTH_USER"];