I am using windows authentication in my web.config file as follow:
<authentication mode="Windows" />
I enabled Anonymous user from IIS and enabled Integrated Windows Authentication, when i disabled Anonymous user I was prompt to enter user name and password with windows logon dialog box, and giving my user name and password does not help, instead i got that i am not authorised to view the page.
Actually my boss wanted the Anonymous user should be disabled...
My code behind in C# is as follow:
1 public static string GetCurrentUsername()
2 {
3 string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;//It does not assign value to variable user
4 //string user = HttpContext.Current.Request.ServerVariables["LOGON_USER"];//This does not work either
5 int domainIndex = user.IndexOf(@"\");
6 if (domainIndex != -1)
7 return user.Substring(domainIndex + 1);
8 return user;
9 }
Thanks