Im new to asp.mvc. I\'m trying to develop a portal to maintain employee data. In my system only \"Manager\" has the rigths to create employee. How do I enable the link when
You could use roles. The first and most important thing is to decorate the controller action that is supposed to perform the update with the Authorize
attribute and specify the correct roles that the user must posses in order to access this controller action:
[HttpPost]
[Authorize(Roles = "Managers")]
public ActionResult Create(Employee emp)
{
...
}
Once everything is secure on the server you could do cosmetics in the view and show the link only if the user is in the Managers
role:
@if (User.IsInRole("Managers"))
{
@Html.ActionLink("Create employee", "Create")
}
You may take a look at the following article for more information about forms authentication and roles.