I'm trying to filter the routes based on the permissions assigned to user, here is my override in BaseController
:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
string userId = User.Identity.GetUserId();
controllerName = filterContext.RequestContext.RouteData.Values["Controller"].ToString().ToLower();
actionName = filterContext.RequestContext.RouteData.Values["Action"].ToString().ToLower();
hasParam = filterContext.ActionParameters.Where(d=>d.Value!=null).Count();
if (!User.IsInRole("Administrator"))
{
if (controllerName == "campaign" && actionName == "index" && !IdentityHelper.HasPermission("CanAddCampaignApplication", userId))
{
filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { controller = "dashboard", action = "Index" }));
}
}
base.OnActionExecuting(filterContext);
}
The code is working fine on local machine, but the issue when I host the site is:
When I request the following Url, user redirected to the dashboard successfully
mysite.com/Campaign
But when I change from Campaign
to campaign
as follow:
mysite.com/campaign
The user got access to the requested URL instead of redirecting to the dashboard, I've searched a lot but I didn't get the issue yet, Please Help.
Thanks in advance