【问题标题】:Can't connect to SQL Server with Windows authentication with my ASP.NET Core application (IIS server)无法使用我的 ASP.NET Core 应用程序(IIS 服务器)通过 Windows 身份验证连接到 SQL Server
【发布时间】:2022-08-20 02:24:15
【问题描述】:

将 ASP.NET Core 3.1 应用程序部署到 IIS 时出现问题。

当我在 appsettings.json 文件中提供 Windows 凭据时,我总是收到此错误:

使用 DOMAIN\\USERNAME$ 登录失败

我应该在我的web.config 中更新连接字符串还是在 IIS 管理器中更新我的 IIS 服务器?

appsettings.json:

{
    \"AppSettings\": {
        \"Secret\": \"9HGXuFLr5PeSjhBBgvMM8CYCQkCcfFgWgQFQvX9M6ahsHC87ESH3cVajpnfTHEBJ\"
    },
    \"Logging\": {
        \"LogLevel\": {
            \"Default\": \"Debug\",
            \"System\": \"Information\",
            \"Microsoft\": \"Information\"
        }
    },
    \"AllowedHosts\": \"*\",
    \"ConnectionStrings\": {
        \"L4LAuthentification_TEST01DataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=L4LAuthentification_TEST01;Integrated Security=True;\",
        \"L4Authentification_RECET01DataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=L4Authentification_RECET01;Integrated Security=True;\",
        \"DevInfoCDataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=DevInfoC;Integrated Security=True;\",
        \"InfocentreRecet01DataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=InfocentreRecet01;Integrated Security=True;\",
        \"L4LGestionFLux_TEST01DataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=L4LGestionFLux_TEST01;Integrated Security=True;\",
        \"L4GestionFlux_RECET01DataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=L4GestionFlux_RECET01;Integrated Security=True;\",
        \"L4EdiFluxInDataBase\": \"Server=SRVSQL-01-TST\\\\INSTANCE1;Database=L4EdiFluxIn;Integrated Security=True;\",
    }
}
  • 我已将我的 cmets 更新为答案,因为它似乎确实让您走上了正确的道路。

标签: sql-server asp.net-core iis windows-authentication


【解决方案1】:

谢谢大家,我在应用程序池中更新了我的身份以使用我的 Windows 帐户并且它有效! image update identity in application pool

【讨论】:

    【解决方案2】:

    每当您使用“Integrated Security=True”时,您都需要知道您的代码正在运行哪个身份(又名主体)。并且该 IIdentity(在 IIS 中运行您的进程)必须具有 SqlServer 的凭据。 –

    最有可能的是,您的 IIS 以“DOMAIN\USERNAME$”的身份运行您的应用程序。 并且(相应地)帐户 DOMAIN\USERNAME$ 没有您的 ms-sql-server 的凭据。

    您很可能会创建一个更加独立的“服务帐户”,用于运行您的 IIS 应用程序并且对您的 Ms-Sql-Server 具有权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      相关资源
      最近更新 更多