Creating an admin page in asp.net mvc 5
Solution 1
You could start by adding an AdminController
and then give it some Actions
.
You could place the [Authorize]
attribute above the controller so that only admins are able to access all actions from this controller, something similar to below:
[Authorize(Roles = "Admin, AnotherRole")]
public class AdminController : Controller
{
public ActionResult Index()
{
return View();
}
}
Solution 2
right click on the controller folder in your source control and then add the name of your controller like "Admin" and then when the controller is created open it up and you will see an index actionresult method created...right click inside it and click on add view and a view will be added...then on the index method in the controller you should add [Authorize(Roles = "admin")] right ontop of your actionresult method....replace that admin with the administrator role name...Hope that helps. this article could also be used as a reference. Part 4: Adding an Admin View
Keeper01
Updated on June 27, 2022Comments
-
Keeper01 almost 2 years
I started with the basic tutorial http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started .
I've added 2 roles in the database table AspNetRoles (yes the DB was also generated automatically)
Now I'm looking for tutorials to create an admin page. because I don't know where to start. Can any of you put me in the right direction.
-
Chris Pratt about 10 yearsPlease refrain from adding answers that just consist of a link to a webpage. Often links go bad, and when they do, your answer is useless. You can provide the link as reference, but you need to also include the relevant code/concepts in your answer, so it can stand on its own, without the link.
-
Siwoku Adeola about 10 yearsI have edited it and used the link as a reference.