I'm trying to access a method of my MVC HomeController from another controller to redirect the user to the homepage if he is not authenticated. The problem is that the Session in my HomeController is not setted if I instantiate it on my own, but I have to access a variable stored in the session from my HomeController. I tried to solve the problem this way:
HomeController currentHomeController = new HomeController();
currentHomeController.Session = this.Session;
return currentHomeController.Index();
But the Session variable has no setter so this does not work. Is there a different way to do this?
My Solution
This works:
return RedirectToAction("Index", "Home");
Thanks for your answers!