相關的Info很多,希望不要忘記。我們希望自動 Windows 登錄到我們域中的 Intranet 網站。為了在客戶端上進行測驗,我使用了將網站列入白名單的 chrome 瀏覽器。服務器運行運行 ASP.NET 5 網站的 IIS 版本 10.0.19041。它連接到同一域中的資料庫 MS SQL Server。連接字串具有引數Integrated Security=SSPI并適用于在客戶端本地運行的應用程式。
這就是現在發生的事情:通常該網站會要求提供憑據,但由于它在白名單中,我假設它現在使用 Windows 憑據,這里如何解釋https://stackoverflow.com/a/24875309/15631999
using (SqlConnection Verbindung = new SqlConnection(sqlConnectString))
{
Verbindung.Open();
拋出“用戶登錄失敗”錯誤,因為它嘗試連接活動的網路服務器用戶,而不是自動登錄的客戶端。 System.Security.Principal.WindowsIdentity.GetCurrent().Name回傳 AppPool 中的賬戶標識。
我們做了什么:(可能并非都相關......)
過去幾天,我們在 Google 上搜索了很多內容,以了解該怎么做。一般關鍵字似乎是 Windows 身份驗證,可能是模擬,NTLM。因此,我們將身份驗證添加到 ConfigureServices。現在看起來像這樣:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews()
.AddXmlSerializerFormatters()
.AddXmlDataContractSerializerFormatters();
services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.Ntlm);
services.AddSession();
services.AddAuthorization(options =>
{
options.AddPolicy("AuthorizationMode", (policy) =>
{
//unauthenticated
policy.RequireAssertion((e) => true);
});
});
//services.AddMvc();
services.AddHttpContextAccessor();
}
我們也嘗試過IISDefaults.AuthenticationScheme授權和不授權。
配置函式片段:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
SessionOptions s = new SessionOptions();
s.IdleTimeout = System.TimeSpan.FromMinutes(30);
s.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
s.Cookie.Name = ".acclaro.de.Session";
s.Cookie.IsEssential = true;
app.UseSession(s);
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
(...)
在 IIS/Sites/[Website]/Authentication 中,我們禁用了匿名身份驗證并啟用了 Windows 身份驗證。這意味著,我認為,我不必編輯 web.config。
We tried it both with Impersonation enabled and disabled. Basic Authentication seem to always ask for Username and PW. So this is not what we want.
We read that I have to change the order of the Providers. Putting Negotiate under NTLM, or downright deleting it doesn't change anything.
I also read that I have to add SPNs. So I executed setspn -a http/[url] [domain controller computer name] at our domain controller.
I don't know what I'm missing. Maybe I just haven't tried the right combination yet. If anyone can help, that would be appreciated. ( Also I hope impersonating other users won't produce problems, when I write in a local temp folder on the Server. I had some Access denied Exceptions in the past. )
If some relevant info is missing, please tell me.
uj5u.com熱心網友回復:
Windows 身份驗證意味著模擬是一個常見的誤解。當用戶使用 Windows 集成身份驗證對服務器進行身份驗證時,服務器上的代碼不會自動以該用戶身份開始運行。
企業 Web 應用程式的正常配置是讓 IIS 使用 Windows Auth 對用戶進行身份驗證,但使用 IIS 應用程式池標識連接到 SQL Server。
如果您希望用戶通過 Web 應用程式以自己的身份連接到 SQL Server,這稱為“模擬”,您需要啟用和配置它。這里有一個 SO question ,顯示了如何在中間件中執行模擬。但可能需要額外的配置,例如 Kerberos 約束委派配置。
這樣做的缺點是
配置是額外的作業,您可能需要網路管理員的幫助。
如果用戶可以通過應用程式直接連接到資料庫,他們也可以通過其他工具來實作。因此,安全管理更加困難,風險也更大。
用戶不能重用連接,所以你會有很多空閑的連接。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/418277.html
標籤:
