2017-12-05 4 views
0

Ich habe eine ASP.NET Core-Webanwendung und ich dekoriere ein paar Controller-Action-Methoden mit Authorize Attribut.Nicht umleiten, um einzuloggen, wenn nicht autorisiert

Also, wenn ich nicht angemeldet bin, tut es keine Umleitung und zeigt mir nur eine leere Seite für diese Controller-Aktion. Ich habe ein paar Tutorials durchlaufen und sie sprechen über Cookie-Authentifizierung. Unten ist meine Configure-Methode in Startup.cs.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
    ILoggerFactory loggerFactory) 
{ 
    loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
    loggerFactory.AddDebug(); 

    app.UseApplicationInsightsRequestTelemetry(); 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationScheme = "MainCookie", 
     LoginPath = "/Login", 
     AccessDeniedPath = "/Home/Forbidden/", 
     AutomaticAuthenticate = true, 
     AutomaticChallenge = false 
    }); 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationScheme = "ExternalCookie", 
     AutomaticAuthenticate = false, 
     AutomaticChallenge = false 
    }); 
    app.UseGoogleAuthentication(new GoogleOptions() 
    { 
     ClientId = "*****", 
     ClientSecret = "*****", 
     SignInScheme = "ExternalCookie" 
    }); 
    app.UseFacebookAuthentication(new FacebookOptions() 
    { 
     SignInScheme = "ExternalCookie", 
     AppId = "AppId", 
     AppSecret = "AppSecret" 
    }); 
    app.UseLinkedInAuthentication(new LinkedInOptions() 
    { 
     SignInScheme = "ExternalCookie", 
     ClientId = "*****", 
     ClientSecret = "*****", 
     ProfileScheme = LinkedInDefaults.ProfileLoadFormat.AppDefined 
    }); 

    if (env.IsDevelopment()) 
    { 
     app.UseDeveloperExceptionPage(); 
     app.UseBrowserLink(); 
    } 
    else 
    { 
     app.UseExceptionHandler("/Home/Error"); 
    } 

    app.UseApplicationInsightsExceptionTelemetry(); 

    app.UseStaticFiles(); 

    app.UseSession(); 
    app.UseMvc(routes => 
    { 
     routes.MapRoute(
      name: "default", 
      template: "{controller=Home}/{action=Index}/{id?}"); 
    }); 
} 

Meine Tätigkeit hier,

[Authorize] 
[HttpGet("https://stackoverflow.com/questions/ask", Name = "askquestions")] 
public IActionResult Ask() 

Antwort

0

Sieht aus wie Sie Login-Seite zu sehen, erwarten sind, wenn der Benutzer nicht authentifiziert ist seit AutomaticChallenge Eigenschaft auf false konfiguriert, werden Sie nicht auf die umleiten Loginseite. Dieses Verhalten ist von Entwurf. Weitere Details here

Verwandte Themen