从 Windows 网络检索网络用户名

本文关键字:网络 用户 检索 Windows | 更新日期: 2023-09-27 18:37:11

请原谅我对这篇文章的天真,因为我习惯于在 LAMP 环境中开发,而不是在 Microsoft .NET 环境中开发,所以我在这里有点超出我的舒适区。

我正在Windows网络上开发一个单页Intranet。 用户根据活动目录 Windows 2008 服务器进行身份验证。 我希望我的 Intranet 页面能够无缝收集经过身份验证的用户的网络用户名,而无需再次输入凭据。 我已经能够获得用户名,但只有在浏览器强制第二次登录之后。

我正在运行 IIS 7 并对其进行了配置,以便:

Anonymous User is disabled
Integrated Windows Authentication is enabled

我的 web.config 文件包含以下文本:

<identity impersonate="false"/>
<authentication mode="Windows"/>
<authorization>
  <deny users="?"/>
</authorization>

我的 C# 代码如下:

public partial class AuthUser : System.Web.UI.Page {
  protected void Page_Init( object sender, EventArgs e ) {
    Response.Write(User.Identity.Name);
  } 
} 

所以我的问题是:

如何在没有第二次身份验证的情况下实现收集登录用户网络用户名的无缝身份验证?

从 Windows 网络检索网络用户名

使用 Active Directory 自动登录只能在 IE 中实现,方法是将站点添加到受信任的站点(

您这样做了),并在自定义级别>>更改 IE>> Internet 选项>>(选择受信任的站点)中的设置(选择受信任的站点):

User Authentication >> Logon >> Automatic logon with current user name and password.