我正在编写一个ASP.NET v4.5.2 Windows应用程序/ Windows窗体供我们的销售团队使用,我不希望他们必须登录。我想比较他们的Windows域名/ userid到我在数据库中进行身份验证的用户标识。我可以使用以下命令在Visual Studio中正确显示域/用户ID:
string userLogin = Request.LogonUserIdentity.Name;
但是当我将应用程序部署到我们的服务器时,这就是显示的内容:
NT AUTHORITY\IUSR
服务器是2012运行IIS 8,以下是此网页的设置:
Anonymous Authentication: Enabled
ASP.NET Impersonation: Disabled
Basic Authentication: Enabled
Digest Authentication: Disabled
Forms Authentication: Disabled
Windows Authentication: Enabled
我读过这个: Get Domain User ID in ASP.NET 并遵循说明但遇到问题。
第一个问题是,当我在IIS中禁用匿名身份验证时,我得到404 - 文件或目录未找到错误。
另一个问题是,当我将此标记放在web.config
中时<authorization>
<deny users="?"/>
</authorization>
我也得到404错误。
我还将web.config中的身份验证模式更改为:
<authentication mode="Windows" />
仍然会收到404或不正确的域/用户信息(取决于IIS设置)。
我已经启动了一个名为test的项目来调试此问题。
当我在IIS中禁用匿名身份验证时,网址会更改为: 服务器名/测试/帐号/登录?/ RETURNURL =%2Ftest%2FAccount%2FLogin%3FReturnUrl%3D%252Ftest%252FAccount%252FLogin%253FReturnUrl%253D%25252Ftest%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252Ftest%2525252FAccount%2525252FLogin%2525253FReturnUrl% 2525253D%252525252Ftest%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252Ftest%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252Ftest%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252Ftest%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252Ftest%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl% 25252525252525253D%2525252525252525252Ftest%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252Ftest%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FR eturnUrl%252525252525252525253D%25252525252525252525252Ftest%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252Ftest%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252Ftest%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252Ftest%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252Ftest%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin% 2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252Ftest%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLog在%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252Ftest%25252525252525252525252525252525252F
请记住,我正在编写自己的登录信息,而不是使用.NET。
如果这是一个重复的问题我很抱歉,但我已经在这里和其他博客上做了很多阅读,并且无论我尝试什么,仍然会得到相同的行为。
提前感谢您的帮助。