Get Username for logged in user
-
I am having trouble getting a logged in username to use on an intranet site. I use HttpContext.Current.Request.ServerVariables["LOGON_USER"] I Get "Network Service". If I run the application in debug locally I get the Domain\username but not when I run it on our intranet. I think its related about web.config and IIS 7 settings. How can I fix it? Thanks...
-
I am having trouble getting a logged in username to use on an intranet site. I use HttpContext.Current.Request.ServerVariables["LOGON_USER"] I Get "Network Service". If I run the application in debug locally I get the Domain\username but not when I run it on our intranet. I think its related about web.config and IIS 7 settings. How can I fix it? Thanks...
Try using HttpContext.Current.User.Identity.Name
-
or System.Web.HttpContext.Current.Request.LogonUserIdentity.Name; if you want the SAMAccountName or
public string Whoami()
{
string str;
int idx;
str = System.Web.HttpContext.Current.Request.LogonUserIdentity.Name;
idx = str.IndexOf("\\");
return str.Substring(idx + 1);
}if you don't want the Domain in there.
..and water fell from the sky like rain.