2017-08-22 36 views
0

我试图使用Azure AD实现身份验证。在应用程序设置中,我将回复URL设置为https://example.com/myapp/login.aspx。 当我登录时,它将我重定向到https://example.com而未指定URL https://example.com/myapp/login.aspx重定向到根的Azure Active Directory响应URL

如何确保它重定向到正确的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() 
     }); 
} 

回答

2

你如何触发登录流程?如果您按照示例https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect/blob/master/WebApp-OpenIDConnect-DotNet/Controllers/AccountController.cs中的示例并通过调用Challenge启动登录,则可能需要确保AuthenticationProperties中的RedirectUri指向您最终(如在,AFTER身份验证中)想要着陆的URL。 我知道,这是令人难以置信的混淆--OIDC选项中的RedirectUri属性指向您想要在auth协议中使用的重定向,您想在其上接收auth令牌 - 而AuthenticationProperties中的那个是本地URL希望在与身份提供商交换后成功完成重定向。由于历史原因,这些过程具有相同的名称。

0

在我的情况下,网站是在虚拟目录(在应用程序中转换)。对于登录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);