gpt4 book ai didi

c# - CurrentPrincipal.Identity.Name 为空

转载 作者:行者123 更新时间:2023-11-30 14:10:23 27 4
gpt4 key购买 nike

我正在尝试使用 System.Threading.Thread.CurrentPrincipal.Identity.Name 获取正在使用 ASP.NET 应用程序的用户的登录信息。我没有收到任何构建错误,但它返回一个空白值。我正在使用 IIS 6,这是我的身份验证设置:

  • 匿名身份验证:禁用
  • ASP.NET 模拟:已禁用
  • 基本身份验证:已启用
  • Windows 身份验证:已启用

我的 Web.config 文件中也没有授权设置。这是我用来尝试获取登录名的方法:

    public void SetUser()
{
string login = System.Threading.Thread.CurrentPrincipal.Identity.Name;
}

我有一个断点来检查值,它显示 login = ""

如何获取登录信息?

编辑

这是我的认证图片:enter image description here

最佳答案

Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

为我工作。我遇到了同样的问题。

关于c# - CurrentPrincipal.Identity.Name 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24310050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com