asp.net C# windows authentication iss config
- by user1566209
I'm developing a webpage where a need to know the users windows authentication values, more precisely the name.
Others developments have been done with this kind of authentication but sadly for me their creators are long gone and i have no contact or documentation.
I'm using Visual Studio 2008 and i'm accessing a webservice that is in a remote server. The server is a windows server 2008 r2 standard and is using ISS version 7.5.
Since i have the source code of the other developments what i did was copy paste and was working fine when i was calling the webservice that was in my machine (localhost).
The code is the following:
//1st way
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
string strUser = wp.Identity.Name;//ALWAYS GET NT AUTHORITY\NETWORK SERVICE
//2nd way
WindowsIdentity winId = WindowsIdentity.GetCurrent();
WindowsPrincipal winPrincipal = new WindowsPrincipal(winId);
string user = winPrincipal.Identity.Name;//ALWAYS GET NT AUTHORITY\NETWORK SERVICE
//3rd way
IIdentity WinId = HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
string userstr = wi.Name; //ALWAYS GET string empty
btn_select.Text = userstr;
btn_cancelar.Text = strUser;
btn_gravar.Text = user;
As you can see i have here 3 ways to get the same and in a sad manner show my user's name.
As for my web.config i have:
<authentication mode="Windows"/>
<identity impersonate="true" />
In the IIS manager i have tried lots of combination of enable and disable between Anonymous Authentication, ASP.NET Impersonation, Basic Authentication, Forms Authentication and Windows Authentication.
Can please someone help me??
NOTE: The respective values i get from each try are in the code