Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Hello,
 
I am developing a  web application in Asp.Net C#. I have a filter with four options. user can select anyone from that filters and then URL will be changed according. I am writing rules for them in my Global.aspx file. I have implemented urls but those are not perfectly working.
I am giving you my webiste link to check urls
 
URL are not working according to  filters
here is my website link
 
<a href="http://www.partykaro.com/Delhi/Events"></a>http://www.partykaro.com/Delhi/Events 


What I have tried:

C#
routes.MapPageRoute("event-listing-city", "{city}/events/{category}/{PriceRange}/{EventEntry}/{PropertyType}", "~/EventListing.aspx", false, new RouteValueDictionary {{"category", "all"}, {"PriceRange", "price"}, {"EventEntry", "entry"}, {"PropertyType", "ptype"} });

        routes.MapPageRoute("event-listing-zone", "{city}/{zone}/events/{category}/{PriceRange}/{EventEntry}/{PropertyType}", "~/EventListing.aspx", false, new RouteValueDictionary {{"category", "all"}, {"PriceRange", "price"}, {"EventEntry", "entry"}, {"PropertyType", "ptype"} });

        routes.MapPageRoute("event-listing-locality", "{city}/{zone}/{locality}/events/{category}/{PriceRange}/{EventEntry}/{PropertyType}", "~/EventListing.aspx", false, new RouteValueDictionary {{"category", "all"}, {"PriceRange", "price"}, {"EventEntry", "entry"}, {"PropertyType", "ptype"} });
Posted
Updated 21-Dec-16 22:33pm

1 solution

The segment events is in all routes, logically it can be removed or put in front. Also you should add an ApiController 'EventsController' to service the requests instead of this page thingy it can then structure calls to your EventsListing.aspx if you like.

Actually it looks like you only ultimately have one route, but even better than suggestion below is if you consider using different actions on that controller with implicit defaults (meaning instead of having a parameter with a default on the route just don't have that part of the route and implement the default in the action.

C#
RouteTable.Routes.MapHttpRoute(
                name: "omnirout",
                routeTemplate: "events/{city}/{zone}/{locality}/{category}/{pricerange}/{evententry}/{propertytype}",
                defaults: new { controller = "Events", action = "GetEvents", city = "all", zone = "all", locality = "all", category = "all",  pricerange="all", evententry = "all", propertytype = "all" } 
            );


maybe more intuitive is to omit the defaults and have more, remember that the routes are evaluated sequentially and you can use your route with defaults as the fallthrough catchall

C#
RouteTable.Routes.MapHttpRoute(
                name: "allevents-in-city-zone-route",
                routeTemplate: "events/{city}/{zone}",
                defaults: new { controller = "Events", action = "GetAllEventsInCityZone"} 
            );
RouteTable.Routes.MapHttpRoute(
                name: "allevents-in-city-route",
                routeTemplate: "events/{city}",
                defaults: new { controller = "Events", action = "GetAllEventsInCity" } 
            );
RouteTable.Routes.MapHttpRoute(
                name: "allevents-route",
                routeTemplate: "events",
                defaults: new { controller = "Events", action = "GetAllEvents" } 
            );
RouteTable.Routes.MapHttpRoute(
                name: "omnirout",
                routeTemplate: "events/{city}/{zone}/{locality}/{category}/{pricerange}/{evententry}/{propertytype}",
                defaults: new { controller = "Events", action = "GetEvents", city = "all", zone = "all", locality = "all", category = "all",  pricerange="all", evententry = "all", propertytype = "all" } 
            );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900