Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does HttpContext.Current.User.Identity.Name return blank

I created a site. It is an internal site. It is a .NET 4.0 site. I would like to grab the username using HttpContext.Current.User.Identity.Name of the person browsing the site. There isnt a login page since it is internal. I am not sure what I am missing. Do I need the following in my webconfig:

<authentication mode="Windows"></authentication>
<identity impersonate="true"/>
<authorization>
  <allow users="?"/>
</authorization>

and this:

  <system.webServer>
  <validation validateIntegratedModeConfiguration="false" />

like image 745
obautista Avatar asked Oct 20 '11 17:10

obautista


People also ask

What does HttpContext current user identity Name return?

It just holds the username of the user that is currently logged in. After login successful authentication, the username is automatically stored by login authentication system to "HttpContext.Current.User.Identity.Name" property.

How do you set HttpContext user identity for an application manually?

You can achieve this by manually settings HttpContext. User: var identity = new ClaimsIdentity("Custom"); HttpContext. User = new ClaimsPrincipal(identity);

Is HttpContext secure?

HttpContext isn't thread-safe.


1 Answers

It comes up blank when unauthenticated. You can verify this by also doing:

HttpContext.Current.User.Identity.IsAuthenticated

Check your authentication level in IIS, is it set to enable windows authentication there too?

like image 166
Brian Mains Avatar answered Oct 03 '22 05:10

Brian Mains