Last post Dec 05, 2013 07:07 AM by amalbala
Dec 05, 2013 05:35 AM|amalbala|LINK
I am trying to show a modal popup to inform the user that the link/action/resource he selected is no authorized for his role. I have decorated the function with a custom annotation
[AutorizacionUsuarios (Roles = "Informatico") ]
And Override the HandleUnauthorizedRequest
protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext)
filterContext.Result = new System.Web.Mvc.HttpStatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
But it generates a new page/view with the error info, I would need to show a modal popup dialog on the view/controller that generate the call to the unauthorized functions.
As an example:
If call the funtion Home/GoToClientsList from a button on Home/Index that redirecto to Clients/Index and this function is not authorized for the usere's roles then I would like to show a modal popup on Home/Index informing the user about.
Dec 05, 2013 06:56 AM|DarrellNorton|LINK
See this solution: http://stackoverflow.com/questions/2174713/asp-net-mvc-authorize-attribute-to-launch-a-modal
Dec 05, 2013 07:07 AM|amalbala|LINK
Thanks for the info!
The problem with this solution is that the "error message" is shown on
filterContext.Controller.ViewData["OpenAuthorizationPopup"] = !isAuthorized;
Where filterContext.Controller is the controller that has the restricted function (in my case ClientsController) but I would like to show the modal on the page that calls this controller.function, in my case HomeController not in ClientsController.
I am trying to put on ViewData or TempData the url of the controller that make the call, but It is a bit weird, would be better If I could get the original controller.