我想在OnGet上允许匿名,但在Razor页面上的OnPost上授权。以下是我想要的。
[Authorize]
public class LogoutModel : BasePageModel
{
[AllowAnonymous] // <========== This is the the issue. I can't use attribute here
public IActionResult OnGet()
{
return LocalRedirect("/");
}
public async Task<IActionResult> OnPost(string returnUrl = null)
{
await HttpContext.SignOutAsync();
return LocalRedirect("/Login");
}
}
我在Startup.cs
尝试过此操作,但这允许在Get and Post上匿名操作
services.AddRazorPages(options =>
{
options.Conventions.AllowAnonymousToPage("/Account/Logout");
});