[英]Not redirect to login when not authorized
I have an ASP.NET Core web application and I am decorating a few controller action methods with Authorize
attribute. 我有一个ASP.NET Core Web应用程序,并且正在用Authorize
属性修饰一些控制器动作方法。
So, when I am not logged in, it doesn't do any redirect and only shows me a blank page for that controller action. 因此,当我未登录时,它不会执行任何重定向,只会向我显示该控制器操作的空白页面。 I have gone through a couple of tutorials and they talk about Cookie authentication. 我已经看过一些教程,他们谈论了Cookie身份验证。 Below is my Configure method in Startup.cs. 下面是我在Startup.cs中的Configure方法。
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?}");
});
}
My action here, 我在这里的动作
[Authorize]
[HttpGet("/questions/ask", Name = "askquestions")]
public IActionResult Ask()
Looks like you're expected to see login page, if the user is not authenticated Since you configured AutomaticChallenge
property to false, you won't redirect to the login page. 如果用户未通过身份验证,则似乎应该看到登录页面。由于将AutomaticChallenge
属性配置为false,因此不会重定向到登录页面。 This behaviour is by design. 此行为是设计使然。 More details here 在这里更多细节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.