How to access serverVariable like AUTH_USER in Dot net core

978 views Asked by At

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

2

There are 2 answers

0
Dmitry On BEST ANSWER

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"];
0
downernn On

The previous answer is correct, but there is also this shortcut:

var authUser = HttpContext.GetServerVariable("AUTH_USER");

More info here.