Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContext.Current.User.Identity.Name returns blank

I am using HttpContext.Current.User.Identity.Name to get the user name when the web application is in use. During development I was using my local iis, with integrated windows authentication enabled and anonymous access enabled and disabled, and I was able to get the username.

Now, when I publish the web application, it comes back blank. The setup on the published server is the same, and I have tried using Page.User.Identity.Name, which also returned blank.

Does anyone know why this is and how to fix it?

like image 599
Andy5 Avatar asked Nov 14 '12 18:11

Andy5


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);


2 Answers

When working with WIF you should use Thread.CurrentPrincipal.Identity.Name instead of User.Identity.Name.

Read more here: http://msdn.microsoft.com/en-us/magazine/ff872350.aspx to learn more about Windows Identity Foundation

Similar question: User.Identity.Name is null after authenticate via WIF

like image 55
Kacper Ryniec Avatar answered Sep 23 '22 01:09

Kacper Ryniec


HttpContext.Current.Request.LogonUserIdentity.Name always work for me in VS 2012 environment and IIS 7

like image 23
Tony Dong Avatar answered Sep 19 '22 01:09

Tony Dong