Take the 2-minute tour ×

I have to install a ASP.NET site in a intranet network. I'm using a authentication mode=Forms". In a my page i need to get the domain\user of the user connected.

I've followed this article: http://support.microsoft.com/kb/306359

But it doesn't work. My web.config has:

 <identity impersonate="true"/>
<authentication mode="Forms" >
          <forms name="login" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx" timeout="30000" />
  <deny users = "?" />
  <!-- This denies access to the Anonymous user -->
  <allow users ="*" />
  <!-- This allows access to all users -->

I'm using IIS 6 and .net 4 In Authentication methods settings of iis i've checked

-Enable anonymous access
-Integrated windows authentication

How can i do?


share|improve this question
Is there a reason that you are not using mode="windows"? Doing that would put the windows username in HttpContext.Current.User.Identity.Name. –  Klaus Byskov Pedersen Feb 11 '11 at 17:23
Beacuse if i use mode="windows" the user is obliged to insert his user name and password if isn't logged. i want get the username if user is logged otherwise do nothing –  Luca Romagnoli Feb 11 '11 at 17:35
You cannot get the Windows username when using Forms authentication. You either have to use Windows authentication or have the user pass through a separate site which has Windows authentication which could pass back the user's Windows username to the Forms authenticated site (passed back either directly or via a lookup value.) –  300 baud Feb 11 '11 at 20:49
add comment

1 Answer

If you have anonymous access enabled the web-site visitors will all be impersonating the IUSR_MachineName account (or whatever you have configured as the anonymous account).

You need to disable anonymous access so the site will force the user to authenticate with his/her credentials so they will be available in your ASP.NET page. Otherwise the server has no idea who the current user is.

share|improve this answer
add comment

Your Answer


