Cannot get a user via Windows Authentication: “A s

2019-08-27 21:37发布

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.

Screenshot of my IIS authentication screen

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.

2条回答
▲ chillily
2楼-- · 2019-08-27 21:50

When you are prompted to enter the Windows credentials you should use:

servername\username password

instead of:

username password

查看更多
Ridiculous、
3楼-- · 2019-08-27 22:06

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.
查看更多
登录 后发表回答