User-1042970710 posted
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");
else
return Page();
}
}
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?
Thanks.
Imran