2017-01-01 2 views
0

Ich habe zwei URLs in meiner Antwort-URL für die Azure Active Directory-Website-Konfiguration angegeben. Eine, die auf meine lokale Host-Umgebung umgeleitet wird, wenn ich lokalen Code ausführe, und eine, die auf meine von Azure gehostete Website umgeleitet wird, wenn ich die prod-Website betreibe. Aber Azure Active Directory scheint die Einstellung zu ignorieren. Es verwendet nur die eine oder andere URL aber nicht beide dies mein startup.Auth.cs istAzure Active Directory-Website-Umleitung unerwartet

public partial class Startup 
{ 
    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; 
    private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; 
    private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"]; 
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"]; 

    private static string authority = aadInstance + tenantId;  

    public void ConfigureAuth(IAppBuilder app) 
    { 
     app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

     app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

     AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.GivenName; 

     app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions 
      { 
       ClientId = clientId, 
       Authority = authority, 
       PostLogoutRedirectUri = postLogoutRedirectUri,      

       TokenValidationParameters = new TokenValidationParameters 
       {             
        RoleClaimType = "roles" 
       }, 

      });    
    } 
} 

und dieses mein startup.cs

public void Configuration(IAppBuilder app) 
    { 
     ConfigureAuth(app);  
    } 

und schließlich das ist meine web.config Einstellung

<appSettings> 
<add key="ida:ClientId" value="*************************" /> 
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" /> 
<add key="ida:AppKey" value="******************************" /> 
<add key="ida:TenantId" value="****************************" /> 
<add key="ida:PostLogoutRedirectUri" value="url of production website" /> 
<add key="ida:Domain" value="company domain" /> 
</appSettings> 

ich weiß nicht, warum diese Umleitung auftreten

Antwort

1

ich die Lösung gefunden zu meinem Problem

sollten Sie den folgenden Code in OpenIdConnectAuthenticationOptions in Startup.Auth

   Notifications = new OpenIdConnectAuthenticationNotifications() 
       { 
        RedirectToIdentityProvider = (context) => 
        { 
         context.ProtocolMessage.RedirectUri = HttpContext.Current.Request.Url.GetLeftPart(System.UriPartial.Path); 
         context.ProtocolMessage.PostLogoutRedirectUri = new UrlHelper(HttpContext.Current.Request.RequestContext).Action("Index", "Home", null, HttpContext.Current.Request.Url.Scheme); 
         context.ProtocolMessage.Resource = GraphAPIIdentifier;        
         return Task.FromResult(0); 
        }} 

Auf diese Weise umleiten uri dynamisch auf der Maschine basiert Sie es dies hilfreich sein

Hoffnung laufen hinzuzufügen.

Verwandte Themen