我的配置:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCookieAuthentication( new CookieAuthenticationOptions
{
AuthenticationScheme = "MyScheme",
LoginPath = new Microsoft.AspNetCore.Http.PathString( "/Account/Login" ),
AccessDeniedPath = new Microsoft.AspNetCore.Http.PathString( "/Account/Forbidden" ),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
} );
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
我的ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
services.AddAuthentication();
services.AddAuthorization();
}
问题是,当我尝试使用Authorize属性进行任何操作时,服务器只回复httpcode 401,但我想要的是一个httpcode 302。