我有一个部署在 Azure VM 中的 ASP.NET 4.5 Web 应用程序。我已经配置了 IIS 服务器和所有内容,但没有进行身份验证。任何人都可以访问 Web 应用程序。
我想配置我的 Web 应用程序,以便每次尝试访问我的 Web 应用程序的人都会先重定向到 Microsoft Azure Active Directory 登录名。如果用户名和密码是 Azure Active Directory 的一部分,我希望它们进入 Web 应用程序,否则应该会失败。
我看过很多关于部署 Azure 应用服务的教程,看起来非常简单,但是,当您在 Azure 虚拟机中部署 Web 应用程序时,它是如何完成的?
编辑:我找到了一个完全符合我需要的教程,而且效果很好
https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect
但是,如何重定向到在 Web 应用程序加载之前始终要求登录?
最佳答案
为了保证在发送身份验证请求时,无论已经存在什么 session cookie,用户都必须输入凭据,OpenID Connect 将在收到 prompt=login
时采取这种方式> 请求中的参数:
Notifications = new OpenIdConnectAuthenticationNotifications()
{
//
// If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
//
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
AuthenticationFailed = OnAuthenticationFailed,
RedirectToIdentityProvider = (context) =>
{
context.ProtocolMessage.Prompt = "login";
return Task.FromResult(0);
},
}
即使您之前已经登录过 azure ad,使用该参数,系统也会要求用户输入凭据。
关于默认情况下,使用 Azure Active Directory 登录页面托管在 IIS 中的 ASP.NET Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45382145/