[带有Windows身份验证的IIS通过IIS托管mvc应用程序,但是我得到IIS APPPOOL \ APP,我需要连接的Windows用户(与IIS express兼容)

问题描述 投票:0回答:1

我在这里看到了类似的问题,但我根本找不到一个好的解决方案。

我的问题:我有一个需要从连接字符串中检索数据的应用程序,所检索的信息取决于经过身份验证的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>
c# iis windows-authentication iis-express
1个回答
0
投票

听起来您的应用程序总是被模仿为应用程序池标识。

我可以通过]获得正确的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>

第二,请保证您的Windows身份验证未使用应用程序池凭据执行enter image description here

最后,您应该获得正确的凭据。enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.