简体   繁体   English

使用具有多个参数的asp.net路由器重写url

[英]url rewrite using asp.net routers with multiple parameter

i am looking for url rewrite options using asp.net routers with multiple parameter. 我正在使用具有多个参数的asp.net路由器寻找url重写选项。 i have parameters of category and location. 我有类别和位置的参数。 i need to rewrite url with combination of both category and location or category alone or location alone. 我需要使用类别和位置或类别单独或位置组合来重写url。 how to retrieve the search result based on category,location Example 如何根据类别,位置检索搜索结果

www.sample.com/flats-for-rent-india
www.sample.com/flats-for-rent
www.sample.com/india

This is not possible unless you have unambiguous separator pattern that can delimit category and location. 除非您具有可以分隔类别和位置的明确的分隔符模式,否则这是不可能的。 For example, let's say category and location will always be separated by say underscore(_) then you can have two patterns that would do the routing - {term1} or {term1}_{term2} . 例如,假设类别和位置始终由下划线(_)分隔,那么您可以使用两种模式进行路由- {term1}{term1}_{term2} Again note that I am not saying category or location because term1 or term2 can be either and you have to sniff the actual values for the same. 再次注意,我并不是说类别或位置,因为term1或term2可以是任一个,而您必须嗅探相同的实际值。

Most probably, I would go with a single route such as {query} and then have a search algorithm that will search for given query term against both category and location. 最有可能的是,我将使用诸如{query}类的单一路线,然后使用一种搜索算法,该算法将针对类别和位置搜索给定的查询词。

If you are probably looking at exact match ie {query} should give either location or category or combination then you have to probably implement your search accordingly. 如果您可能正在寻找完全匹配的内容,即{query}应该给出位置,类别或组合,那么您可能必须相应地实现搜索。 For example, 例如,

  1. Search the query term against available categories - if match found we are done. 根据可用类别搜索查询词-如果找到匹配项,我们就完成了。
  2. Search the query term against available location - if match found we are done. 根据可用位置搜索查询字词-如果找到匹配项,我们就完成了。
  3. Split the query term with possible separators (eg hyphen(-), underscore or space) - search parts against category/location. 用可能的分隔符(例如,连字符(-),下划线或空格)拆分查询词-根据类别/位置搜索零件。 For example, "flats-for-rent-india" would be split into following pairs 例如,“印度出租公寓”将分为以下几对
    1. flats & for-rent-india 单位和印度租金
    2. flats-for & rent-india 印度公寓出租
    3. flats-for-rent & india 出租公寓和印度
      so now you have to try each pair against available categories and locations - this would probably give you a match at #3. 因此,现在您必须根据可用的类别和位置尝试每一对-这可能会使您在#3比赛。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM