在公共 ASP.NET 网站上获取 Windows 用户名
我正在发布一个公共 ASP.NET 网站。我假设访问者使用的是 Windows 和 Internet Explorer。我想在首页显示 Windows 用户名,可以吗?
我已经在 IIS 中启用了 Windows 身份验证,并且在开发环境中一切正常。在生产环境中,它会不断询问 Windows 登录凭据。
I'm publishing a public ASP.NET website. I'm assuming the visitor is using Windows and Internet Explorer. I want to display the Windows username on the front page, is it possible?
I have already enabled Windows Authentication in IIS and on a development environment everything works fine. On production it keeps asking the Windows login credentials.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Windows 身份验证,用户必须提供可对运行网站的服务器/域进行身份验证的凭据。如果客户端在同一域中运行并经过身份验证,Internet Explorer 将自动处理凭据交换;这就是它在开发环境中工作的原因。但是,当从公共端访问时,Internet Explorer 会尝试移交用户当前使用的凭据(某些其他 Windows 域),但这些凭据无法通过您的服务器进行身份验证,因此 IE 会提示用户输入可以进行身份验证的凭据到该域。
For Windows Authentication, the user must supply credentials that can authenticate to the server/domain in which the website is running. If the client is running within the same domain and authenticated, Internet Explorer will automatically handle the credential exchange; this is why it works in the dev environment. However, when accessed from the public side, Internet Explorer tries to hand over the credentials that the user is currently using (some other Windows domain), but those credentials cannot authenticate to your sever, so IE prompts the user to enter credentials that can authenticate to that domain.
如果它是一个公共网站,那么你就不能这样做。为什么?因为您需要根据您的 AD 验证用户凭据,而您无法在公共网页上执行此操作。 (这完全有道理,否则你怎么知道我是谁?)
如果你在内部网络中执行此操作,其中每个帐户都在你的 Active Directory 中,那么人们只需将该站点添加到他们的受信任站点或本地站点IE 中的网络区使 NTLM 透明地工作。
If it's a public website then you can't do it. Why? Because you would need to verify the user credentials against your AD and you can't do that on a public web page. (Which makes total sense, after all how would you know who I am otherwise?)
If you ARE doing this in an internal network where each account is in your Active Directory, then people just need to add the site to their Trusted Sites or Local Network Zone in IE for NTLM to work transparently.