Best place in MVC for user expiration

I have an ASP.NET MVC web application that has a really basic subscription system to it.

My question is about where it is best to use the end date of the subscription. Currently, Site.master contains the following code:

    if (Profile.expires < DateTime.Today)
    {
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }

Therefore, whenever someone clicks on a page, these codes check to see if their username has expired.

I'm obviously going to move this code from the Site.master page and to Model.Helpers (or something like that), however I was wondering if I still need to call the code from another place (saving in the context of MVC). it’s obvious that I will translate the code from site.master and into, for example, Model.Helpers.Validate ()

from there, the possibilities, as I see it, are as follows:

  • method call from .master site
  • global.asax, , .
  • - ( , )

- , ? , MVC, , . "":)

+3
2

, onAuthorization.

+3

Application.AuthenticateRequest Global.asax. , (AuthorizationService).

var authorizationService = new AuthorizationService(); 

if(authorizationService.IsSubscribtionExpiredForUser(user)) 
{
   // redirect to login page 
}
0

Source: https://habr.com/ru/post/1733811/


All Articles