单个页面的随机和多个URL重写 [英] Random and multiple URL rewriting for a single page

查看:120
本文介绍了单个页面的随机和多个URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

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"} });

推荐答案

段事件在所有路径中,逻辑上可以删除或放在前面。你还应该添加一个ApiController'EventsController'来为这些请求提供服务而不是这个页面,如果你愿意,它可以构建对你的EventsListing.aspx的调用。



实际上它看起来你最终只有一条路线,但是比下面的建议更好的是你是否考虑在该控制器上使用隐式默认值(意味着在路线上没有一个带默认值的参数而不是那个部分)路由并实现操作中的默认值。



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.

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

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" } 
            );


这篇关于单个页面的随机和多个URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆