IIS 和 SQL 服务器 ASP.Net C# Entity Framework Windows 身份验证

IIS and SQL Server ASP.Net C# Entity Framework Windows authentication

我目前正在使用 Windows 身份验证开发 ASP.Net / C# / Entity Framework 项目。

我希望我的用户使用他们自己的 Active Directory 帐户访问 IIS 服务器和 SQL 服务器,允许管理员查看谁连接到数据库。

但我有一个问题:在连接到数据库时,程序使用在 IIS 服务器中设置的应用程序池帐户,而不是他的用户帐户。

这是我的 web.config 文件:

<configuration>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2"/>
        <httpRuntime targetFramework="4.5.2"/>
        <customErrors mode="Off"/>
        <authentication mode="Windows"/>
        <identity impersonate="true"/>
    </system.web>
    <connectionStrings>
        <add name="BOMBuilderEntities"
         connectionString="metadata=
         res://*/Model.BOMBuilderModel.csdl|
         res://*/Model.BOMBuilderModel.ssdl|
         res://*/Model.BOMBuilderModel.msl;
         provider=System.Data.SqlClient;
         provider connection string=
             'data source=FRSDSQ01;
              initial catalog=BOMBuilder;
              integrated security=SSPI;
              MultipleActiveResultSets=True;
              App=EntityFramework'" 
              providerName="System.Data.EntityClient"/>
    </connectionStrings>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="multipages.aspx" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

此外,我尝试修改此 ApplicationPoolIdentity 设置以查看它是否是用于 SQL 服务器身份验证的此连接,确实如此。如果我设置域帐户,该帐户将列在 activity 监视器中。那么如何设置此设置才能使用登录我的 asp.net 应用程序的用户帐户?

编辑 1:我添加了模拟设置。

万一其他人遇到这个问题:
- 使用 基本身份验证 + Asp.Net 模拟 (检查 Web.config 文件和已启用的 IIS 服务器配置),一切正常。用户被要求在应用程序加载期间连接到 IIS 服务器。然后使用用户登录创建到 SQL 服务器的 Entity Framework 连接,这样我们就可以正确监控谁连接了。
- 使用 Windows 身份验证,我仍然遇到匿名登录无法登录 SQL 服务器的问题。我不明白为什么它不使用用户登录...如果有人有想法,我会需要它!

这可能是双跳的情况。这是当 IIS 服务器和 SQL 服务器位于不同机器上时,这是一种安全措施,除非适当的授权到位,否则拒绝继续向链下游的服务器提供凭据。

引自第二篇文章:

Apparently, you can get around the problem and use proper delegation if you set up your network to use Kerberos and set up the web server in question as trusted for delegation.

可以在以下文章中找到更多信息: http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx http://blogs.msdn.com/b/knowledgecast/archive/2007/01/31/the-double-hop-problem.aspx