I am new to .NET, MVC & Identity Framework. I noticed the identity framework allows for securing individual controller actions via annotations.
[Authorize]
public ActionResult Edit(int? Id){
//edit action
}
I would like to secure certain actions based on user permissions.
Example : A blog application where only the user who created a blog post can edit.
With this in mind, is it possible to perform either option below? If so, are there resources and examples on how to best achieve?
[Authorize(Entity = "Entry", Permission = "Edit", Id = Id)]
public ActionResult Edit(int? Id){
//edit action
}
or
[BlogEntryPermission(Permission = "Edit", Id = Id)]
public ActionResult Edit(int? Id){
//edit action
}
Where blog Id
is captured from the request.
Any information or direction on permission based authentication would be most appreciated. Thanks in advance for your help.
You can implement your custom
AuthorizationAttribute
where you will specify your parameters and can get ablogId
from requestThen use it like this: