问题
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.
回答1:
try the below mentioned work around:
- On the Management Server, click Start, click Run, type gpedit.msc, and then click OK.
- Under Computer Configuration, expand Windows Settings, expand Security Settings, expand Local Policies, and then expand Security Options.
- In the Policy pane, right-click Network access: Do not allow storage of credentials or .NET Passports for network authentication, click Properties, click Disabled, and then click OK.
回答2:
When you are prompted to enter the Windows credentials you should use:
servername\username password
instead of:
username password
来源:https://stackoverflow.com/questions/23111915/cannot-get-a-user-via-windows-authentication-a-specified-logon-session-does-no