I have an action I want to restrict only to role "Admin". I did it like this:
[Authorize(Roles = "Admin")]
public ActionResult Edit(int id)
After manually going under Controller/Edit/1 path I'm redirected to login page. Well, that isn't bad maybe, but I want to show 404 instead of it and try to stick using attributes for it. Is that possible?
Sure, you could write a custom authorize attribute:
and then use it:
Remark: you probably want to show a 401 or 403 page if the user is not authorized instead of 404 which is for file not found.
In response to @Daniel's comment on my comment to @Darin's answer this is my implementation: