1

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

Mubsher Mughal
  • 442
  • 8
  • 19
  • 1
    Make a case insensitive comparison using `StringComparison.OrdinalIgnoreCase` (refer [this answer](https://stackoverflow.com/questions/3121957/how-can-i-do-a-case-insensitive-string-comparison) for example) –  Aug 16 '18 at 07:53
  • But I'm already converting the segments to lower case. Even it is still compulsory to make a CI comparison. – Mubsher Mughal Aug 16 '18 at 07:59
  • Can you 100% confirm that the authenticated user your testing is **not** part of the `Administrator` role and does **not** have the permission for `CanAddCampaignApplication`? – Kitson88 Aug 16 '18 at 08:47
  • Yes I'm 100% sure because the matter is Case-sensitivity. – Mubsher Mughal Aug 16 '18 at 08:57
  • thanks @StephenMuecke..It works. – Mubsher Mughal Aug 16 '18 at 10:12

0 Answers0