在生产服务器上运行的应用程序如何访问用户正在访问应用程序的机器的登录用户名?例如,我目前登录到我在INTRA公司内部网上的机器。我的用户名将是INTRA\Username。
我已将特定用户名添加到数据库,并希望根据数据库检查此 Intranet 用户名,以限制对应用程序的访问并在整个应用程序中利用该用户名。
目前,我正在使用以下代码来访问用户名:
Private username As String = Thread.CurrentPrincipal.Identity.Name
这在 localhost 上运行良好,但是在开发服务器上对数据库进行身份验证时,出现以下错误:
用户“NT AUTHORITY\ANONYMOUS LOGON”登录失败。
这是不正确的方法吗?这甚至可能吗,还是安全问题太大了?该应用程序将是在 IE 商店中运行的内部 Intranet 应用程序。已经存在的相关 web.config 部分包括:
<identity impersonate="true"/>
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
<connectionStrings>
<add name="CONNSTR" connectionString="Initial Catalog=DATANAME;Data Source=servername;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>