vendredi 13 mai 2016

Controller Action Method is not getting called when custom routebase class is used

    Following is the Custom RouteBase class 

 public class CustomRoutingBehaviour:RouteBase
        {
            string[] allowedUrl;
            public CustomRoutingBehaviour(string[] url)
            {
                allowedUrl = url;
            }

            public override RouteData GetRouteData(HttpContextBase httpContext)
            {
                RouteData route = null;
                string browsedurl = httpContext.Request.AppRelativeCurrentExecutionFilePath;
                if(allowedUrl.Contains(browsedurl,StringComparer.OrdinalIgnoreCase))
                {
                    route = new RouteData(this,new MvcRouteHandler());
                    route.Values.Add("controller","CustomiziedController");
                    route.Values.Add("action","Index");
                    route.Values.Add("BrowsedURL",browsedurl);

                }

            return route;
            }

            public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
            {
                return null;
            }
        }

Following is the routing configuration: routes.Add(new CustomRoutingBehaviour(new string[] { "~/Customizied/Index", "~/Customizied/Index1" }));

Aucun commentaire:

Enregistrer un commentaire