繁体   English   中英

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

[英]Hosting a mvc app via IIS with windows authentication, but I get IIS APPPOOL\ APP I need the windows user that connects (works with IIS express)

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

我的问题:我有一个应用程序需要从连接字符串中检索数据,而检索到的信息取决于经过身份验证的 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>

其次,请保证您的 Windows 身份验证不使用应用程序池凭据执行在此处输入图片说明

最后,您应该获得正确的凭证。 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM