Last post Aug 07, 2020 11:45 PM by bruce (sqlwork.com)
Aug 07, 2020 09:52 PM|jalali|LINK
In my application after authentication I store my User object in the session and move to another pages. If the session is null I will divert to Login page.
Here is the Code where I check my Session
public class IndexModel : PageModel
public IActionResult OnGet()
var usersLoginInfo = HttpContext.Session.GetObjectFromJson<UsersLoginInfo>("UserInfo");
if (usersLoginInfo == null)
return new RedirectToPageResult("/Login");
What I was thinking to make separate class BasePageModel inherited from
PageModel and then import all my pages from that class i.e
BasePageModel instead of PageModel.
My problem is when I separate the the class and try to override the OnGet method The framework is complaining that the method is not overridable.
I want to avoid checking my session in all my pages....
Is there any work around?
Aug 07, 2020 11:45 PM|bruce (sqlwork.com)|LINK
to override OnGet you need to make it virtual. though I think you have picked a bad design. your authentication logic should be in middleware.