场景:Azure应用程序网关背后的ASP.net MVC应用程序
当未经授权的用户尝试访问使用Authorize属性保护控制器方法的页面时,用户将被重定向到Azure AD登录页面 . 登录后,用户将被重定向到无法访问的应用程序URL(提供403),而不是正确的应用程序网关URL .
我们使用时登录正常工作:
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
所以问题是:是否有一种好方法可以覆盖Authorize属性正在使用的主机名,以便重定向到应用程序设置中指定的应用程序网关URL?
在startup.auth.cs内部,我们使用OpenId Connect并将重定向URI设置为正确的应用程序网关URL,该URL用于成功进行身份验证,但在用户通过身份验证后仍会重定向到错误的URL .
Notifications = new OpenIdConnectAuthenticationNotifications()
{
RedirectToIdentityProvider = (context) =>
{
string appBaseUrl = _siteUrl;
context.ProtocolMessage.RedirectUri = appBaseUrl;
1 回答
从以下问题找到我自己的答案:Redirect user after authentication with OpenIdConnect in ASP.Net MVC
总而言之,可以通过在AuthorizationCodeReceived回调中设置context.AuthenticationTicket.Properties.RedirectUri来实现身份验证后的重定向 .