Cannot get a user via Windows Authentication: “A specified logon session does not exist. It may already have been terminated.”

妖精的绣舞 提交于 2019-12-11 18:16:30

问题


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:

  1. On the Management Server, click Start, click Run, type gpedit.msc, and then click OK.
  2. Under Computer Configuration, expand Windows Settings, expand Security Settings, expand Local Policies, and then expand Security Options.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!