Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContext.Current.User.Identity.Name is Empty

I have a Silverlight application (using MVC) and when i'm building in visual studio, using Visual Studio Development center, there's no problem, the HttpContext.Current.User.Identity.Name has a Value

But when i'm using the same project with IIS 7.5 (i'm using Windows 7), HttpContext.Current.User.Identity.Name stays empty

Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what's wrong in IIS?

like image 860
Jordy Avatar asked Oct 15 '09 08:10

Jordy


People also ask

How do I find HttpContext current user identity Name?

Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an . aspx page without using the fully qualified class reference to HttpContext. For example, you can use User.Identity.Name to get the name of the user on whose behalf the current process is running.

How do you set context user identity?

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


1 Answers

I struggled with this problem the past few days.

I suggest reading Scott Guthrie's blog post Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application

For me the problem was that although I had Windows Authentication enabled in IIS and I had <authentication mode="Windows" /> in the <system.web> section of web.config, I was not preventing anonymous access. This last part was the key. You need to prevent anonymous access to ensure that the browser sends the credentials.

You can either configure IIS in Control Panel so that your site (or machine) uses Windows authentication and denies anonymous access or you can add the following to your web.config in the system.web section:

<authentication mode="Windows" />  <authorization>    <deny users="?"/> </authorization> 
like image 119
Bryan Bedard Avatar answered Sep 21 '22 12:09

Bryan Bedard