我最近更新了一個舊的 4.5 C#.NET webforms 應用程式以使用 ADFS 進行身份驗證,但不知何故,它僅在我還在 IIS 中啟用了 Windows 身份驗證時才有效。當我啟用了 Windows 身份驗證時,在用戶登錄到我們的 ADFS 服務器后,會出現一個 Windows 身份驗證彈出框,要求用戶登錄兩次。這不是我想要的結果,所以我關閉了 Windows 身份驗證,希望第二次登錄會消失,但現在登錄 ADFS 后,用戶收到 401 Unauthorized 錯誤。
如果我必須為該舊版應用程式啟用 Windows 身份驗證才能成功登錄,是否應該在代碼中添加一些內容以防止在用戶登錄 ADFS 后出現 Windows 身份驗證彈出視窗?
啟動.Auth.cs
public partial class Startup
{
private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
// This makes any middleware defined above this line run before the Authorization rule is applied in web.config
app.UseStageMarker(PipelineStage.Authenticate);
}
}
啟動檔案
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
更新:我剛剛確認我的開發站點作業正常 - 這意味著在使用 ADFS 進行身份驗證后,Windows 身份驗證框不會出現。它具有相同的代碼、相同的 web.config、與 live 相比在開發服務器上的 IIS 中的相同設定以及 ADFS 服務器上的相同設定。我能看到的唯一區別是實時服務器Windows Server 2019 Datacenter和開發服務器是Windows Server 2012 R2.
在 ADFS 身份驗證后,這 2 個服務器之間是否會彈出 Windows 身份驗證框?是不是舊版應用程式只能在舊版服務器上運行,而不能在新服務器上運行?
uj5u.com熱心網友回復:
我剛剛在這里找到了我需要的答案: 401 Unauthorized: Access is denied due to invalid credentials
- 打開 IIS
- 選擇站點
- 開放認證
- 編輯匿名身份驗證
- 選擇應用程式池標識
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/384657.html
標籤:C# 。网 验证 adfs ws-federation
上一篇:更改資料庫時如何更新組合框專案?
