Answer the question
In order to leave comments, you need to log in
ASP.NET MVC: how to extend the Controller class?
Good afternoon. Everything happens to me as follows:
The site is divided into 2 areas, public and admin.
I'm just starting with C#, and before that I worked in PHP and, of course, I'm still confused in many types and so on, so don't scold me much.
I would like to be able to extend the Controller class, from which all other controllers are inherited. It would be desirable for each controller to already have a ready-made property - connection to the database.
And in the admin area there would also be a constructor for checking authorization, otherwise it’s not comme il faut for each controller to write an authorization check and stuff data into the properties ...
Thank you in advance.
Answer the question
In order to leave comments, you need to log in
[Authorize]
public class FirstController : Controller
{
// TODO
}
public class SecondController : FirstController
{
public ActionResult Index()
{
return View();
}
}
When accessing /Second/Index redirects to the LogOn page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question