A
A
Andrey Kornev2013-12-01 17:49:52
ASP.NET
Andrey Kornev, 2013-12-01 17:49:52

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

2 answer(s)
S
saiganovv, 2013-12-02
@webkornevand

[Authorize]
public class FirstController : Controller
{
// TODO
}
public class SecondController : FirstController
{
public ActionResult Index()
{
return View();
}
}
When accessing /Second/Index redirects to the LogOn page.

C
Cyril, 2013-12-02
@llirikkkk

why not read books? they describe some of the approaches in sufficient detail.
smarly.net/pro-asp-net-mvc-4
smarly.net/asp-net-mvc-4-in-action

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question