I have recently implemented Roles in MVC application. The controller has various action methods like below:
public class MyController : Controller
[Authorize(Roles = "User, SuperUser")]
public ActionResult DoActionOne() {
// This can be invoked by both user and superuser
}
[Authorize(Roles = "SuperUser")]
public ActionResult DoActionTwo() {
// This can't be invoked by user
// Application will redirect to /Login automatically when 'User' invokes it
}
}
Now, this works good, as desired.
But, I want that when User
is redirected to /Login
due to insufficient Role to access Action method DoActionTwo
in controller, I want to insert a query param, which can be read by /Login
page to show message to user like "Invalid Permissions / Authorization Required". It may be any custom message.
Any ideas ?