I'm trying to use System.Threading.Thread.CurrentPrincipal.Identity.Name
to get the login of who is using an ASP.NET application. I'm not getting any build errors, but it returns a blank value. I'm using IIS 6 and here are my authentication settings:
I have no authorization settings in my Web.config
file either. Here is the method I am using to try to get the login:
public void SetUser()
{
string login = System.Threading.Thread.CurrentPrincipal.Identity.Name;
}
I have a breakpoint to check the value and it says login = ""
.
How can I get the login?
EDIT
Here is my authentication picture:
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Worked for me. I was having the same problem.
I was able to fix it. In my project properties, I was using IIS express so my application wasn't hitting my actual IIS. I unchecked that, created a virtual directory and disabled all authentication except Windows Authentication and it works now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.