.Net核心Razor页面AllowAnonymous on OnGet而不是OnPost

时间:2020-03-20 13:25:21

标签: asp.net-core .net-core authorization razor-pages

我想在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");
 }); 

0 个答案:

没有答案