【问题标题】:How do I use impersonation in dotnet core 1.1?如何在 dotnet core 1.1 中使用模拟?
【发布时间】:2017-06-22 12:36:05
【问题描述】:

我正在尝试使用 Trusted_Connection=True 验证我的 MSSQL 连接。为了让它工作,我安装了 NuGet 包Impersonate.AspNetCore.Windows(Impersonate),并在我的 Startup.cs 中进行设置,如下所示:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseWindowsImpersonation(options => {
        options.Enabled = true;
    });
}

在我的 Program.cs 中,我添加了 UseIISIntegration 来设置 .net 核心以托管在 IIS 中:

public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }

在 IIS 中,我创建了一个新网站,将 ApplicationPool 基本设置更改为 No managed CodeClassic 管道模式。在高级设置中,我将进程模型下的Identity 设置为现有的 Windows 用户帐户:

当我在连接字符串中使用Trusted_Connection=True 时,应用程序无法验证我与 SQL 服务器的连接:

"ConnectionStrings": {
    "DashboardDatabase": "Server=<SOME_SERVER>;Database=<SOME_DATABASE>;Trusted_Connection=True"
}

(当然,其中和替换为服务器和数据库的实际名称)。

我的问题是:我在这里忘记了什么吗?

【问题讨论】:

    标签: c# sql-server .net-core


    【解决方案1】:

    我的设置与您完全相同,并且可以正常工作。您是否将forwardWindowsAuthToken="true" 添加到您的web.config 文件中?如果还没有,您可能需要在应用程序的根文件夹中创建 web.config 文件。见package repo

    仅供参考,我的连接字符串中还有Integrated Security=true;,不确定是否需要。

    【讨论】:

    • 是的,我在我的 web.config 中启用了 forwardWindowsAuthToken(由命令dotnet publish -c Release 生成。我会尝试集成安全部分,认为它与Trusted_Connection 相同跨度>
    猜你喜欢
    • 2017-10-30
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2017-04-18
    相关资源
    最近更新 更多