I have search the web including SO but couldn't find the best solution to the problem. I have taken over a MVC project which has around 15 controllers and each controller class starts with these 2 lines:
int userid = (int)System.Web.HttpContext.Current.Session["UserID"]; string usertype = (string)System.Web.HttpContext.Current.Session["UserType"];
These 2 variables (userid,usertype) are then used throught the controller action methods.
What would be the best way of avoiding this? The 2 options that I found were either creating a SessionEndAttribute class and add it to each controller OR create a base controller class with the session check and make all controller classes inherit from the BaseController class.
Aucun commentaire:
Enregistrer un commentaire