asp.net mvc 4 - Hide the add/edit Action Link in view based on the user roles roles -



asp.net mvc 4 - Hide the add/edit Action Link in view based on the user roles roles -

how can enable or disable add/edit/delete action link in asp.net mvc razor view based on user roles. have tried next seems not working while updating user role.

if have updated user role, updated value did not refresh.it still work old value.how can resolve issue?

if (user.isinrole("admin")) { }

in view, check following:

@{ //replace admin administrator role if (user.isinrole("admin")) { @html.actionlink("edit", "edit", new { id=item.id }) | @html.actionlink("details", "details", new { id=item.id }) | @html.actionlink("delete", "delete", new { id=item.id }) } }

with administrators can see whasts within code block, not mean, users not manually come in url in browser. still reachable. should probalby secure controllers / action methods well:

using system.componentmodel.dataannotations [authorize(roles = "admin, supermoderator")] public actionresult getmesomething() { /* ... */ }

asp.net-mvc-4

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -