我在这里看到了类似的问题,但我根本找不到一个好的解决方案。
我的问题:我有一个需要从连接字符串中检索数据的应用程序,所检索的信息取决于经过身份验证的Windows用户。当我使用IIS Express在开发环境中运行此程序时,我得到了登录用户。
但是,当我通过IIS Local托管它时,我作为用户获得(IIS APPPOOL \)。我需要成为Windows用户。
即使获得登录名,当我在视图中进行检查时,应用程序仍会输出APPPOOL
任何对此有好的解决方案的人?
我尝试过:
@System.Web.HttpContext.Current.User.Identity.Name
@System.Security.Principal.WindowsIdentity.GetCurrent().Name
@HttpContext.Current.Request.LogonUserIdentity.Name
<system.web>
<authentication mode="Windows" />
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>
<identity impersonate="true" />
<trace enabled="true" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
听起来您的应用程序总是被模仿为应用程序池标识。
我可以通过]获得正确的Windows身份>
和匿名。System.Web.HttpContext.Current.User.Identity.Name HttpContext.Current.Request.LogonUserIdentity.Name User.Identity.Name;
首先,请确保您的身份验证如下所示。请同时禁用假冒
<location path="mysite">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>