I use the following code to get a users name in C#. It works perfectly fine on my computer, but as soon as I deploy it to a server it breaks with the error message: "A specified logon session does not exist. It may already have been terminated."
private bool isUserAuthenticated()
{
return System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
}
private string getUserName()
{
return System.Web.HttpContext.Current.User.Identity.Name;
}
My web.config file (excerpt):
<system.web>
<authentication mode="Windows" />
</system.web>
I then proceeded and enabled Windows Authentication for the website on IIS.
Did I miss something? What could be the error here and how can I fix it? Any thoughts are highly appreciated. If you need more information please leave a comment.
When you are prompted to enter the Windows credentials you should use:
servername\username password
instead of:
username password
try the below mentioned work around: