c# - 如何获取 Windows 客户端用户 ASPX C#
问题描述
我在 StackOverflow 上查看并尝试了几十个“答案”,但没有一个有效。我有一个非常简单的 aspx 页面,后面有 C# 代码。该网站位于 Windows 2008R2 服务器上。该网站看起来像(实际名称已更改):
MyServer - set for Anonymous Authentication
Application Pools
ASP.NET v4.0 Classic - .Net 4.0, Classic pipeline, App Pool Identity
MySiteAppPool - .Net 2.0, Integrated, runs under a Domain-wide Service identity (call it "mycompany\domservice")
Sites
MyMainSite - Windows Authentication, uses "MySiteAppPool"
"AutoPrint" - my web app, Windows Authentication, uses "ASP.Net v4.0 Classic" app pool, ASP.NET Impersonation enabled
我的“AutoPrint”网络应用程序有一个起始页“AutoPrint.aspx”和后面的代码(“AutoPrint.aspx.cs”,加上几个类)。
服务器和主站点不可更改,因为该站点下还有其他几个应用程序。
用户当前调用此应用程序:
http://MyServer/AutoPrint
Everything I have tried is returning the "mycompany\domservice" result:
Request.LogonUserIdentity.Name.ToString() - returns "mycompany\domservice"
System.Environment.UserName.ToString() - returns "domservice"
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() - returns "mycompany\domservice"
我在这里想念什么?为什么这么难?
进一步说明:“mycompany\domservice”-“domservice”帐户只是“mycompany”域中的一个 ActiveDirectory 帐户,它有权读取/写入站点和其他应用程序所需的目录。在安装站点和其他网络应用程序时,我们将该帐户用作“连接身份”用户。
我要做的是获取打开浏览器并访问此应用程序的人的 Windows 用户帐户的 ActiveDirectory 名称。如果用户“JJONES”登录 Windows 并使用“ http://myserver/autoprint ”启动应用程序,我想获取“JJONES”或“mycompany\JJONES”作为用户名。
解决方案
如果您使用匿名身份验证,则浏览器不会向服务器发送任何凭据(用户 ID/密码)。因此,如果您想要服务器上的客户端用户 ID,则必须使用非匿名身份验证,例如。窗口或窗体。您可以使用非匿名身份验证,然后允许或拒绝特定用户或用户组或所有用户访问您的网站。
推荐阅读
- javascript - 单击 Next JS 路由和加载页面之间的延迟
- javascript - Cypress - 验证 HTTP 标头响应
- javascript - 更新变量以显示总成本
- xml - 内容类型 `application/xml` 在 Firefox 中显示扁平文本(失去 XML 结构)
- java - Java PDFBox:删除标记PDF中的父元素
- atom-editor - Atom Prettier 在自动保存时在 useEffect 中添加依赖项
- python - 使用矩阵作为正态分布的尺度
- python - TypeError:单例数组数组(0.5)不能被视为有效集合
- android - WebAuthenticator 总是跳过登录页面,如何为新用户获取新的登录表单?
- android - Hilt : 带有 Koin 等参数的字段注入