我正在尝试使用 Azure AD 实施身份验证。在应用程序设置中,我将回复 URL 设置为 https://example.com/myapp/login.aspx。 当我登录时,它会将我重定向到 https://example.com 并且未指定 URL https://example.com/myapp/login.aspx
如何确保它重定向到正确的 URL?以下是启动代码。
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = ConfigurationManager.AppSettings["owin:ClientId"].ToString(),
Authority = "https://login.microsoftonline.com/yz5036e3-2951-4c11-af4d-da019fa6a57d",
RedirectUri = ConfigurationManager.AppSettings["RedirectUri"].ToString()
});
}
如何触发登录流程?如果您遵循示例并通过调用挑战来启动登录,如 https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect/blob/master/WebApp-OpenIDConnect-DotNet/ 所示Controllers/AccountController.cs,您可能需要确保 AuthenticationProperties 中的 RedirectUri 指向您最终(如在身份验证之后)想要登陆的 URL。 我知道,这非常令人困惑 - OIDC 选项中的 RedirectUri 属性指向您想要在身份验证协议中使用的重定向,即您想要接收身份验证令牌的重定向 - 而 AuthenticationProperties 中的属性是您想要的本地 URL在您与身份提供商的交换成功结束后重定向到。由于历史原因,这些属性具有相同的名称。
在我的例子中,网站位于虚拟目录下(在应用程序中转换)。对于登录 URL,例如http://example.com/myapp/login.aspx,它将用户重定向到http://example.com。如果我将 RedirectUri 设置为 myapp/AfterLogin.aspx,它就起作用了。
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "myapp/AfterLogin.aspx", },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
很抱歉在下面添加redirectUrl后回复延迟 -
navigateToLoginRequestUrl= false
希望这会有所帮助