2013-03-20 78 views
1

我有以下网址,我想隐藏查询字符串如下:摘要URL和路由

从这个:

/main?a=3&date_in=20/03/2013&date_out=20/03/2013 

这样:

/main?cars/from/2013/01/27/to/2013/02/26 

其中3指汽车,例如

date_in = from and then the date always on that format 

and date_out = to and then the date always on that format. 

我在global.asax上创建了以下内容:

routes.MapPageRoute("main", "main/{*queryvalues}", "~/default.aspx"); 

有关我该怎么做的任何想法?

+0

良好的格式始终是你的朋友。 – 2013-03-20 07:48:27

+0

非常感谢您的提示,我会做的更好未来的时间:) – carol1287 2013-03-20 07:49:29

+0

任何人都知道这个答案吗? – carol1287 2013-03-21 06:25:30

回答

0

你可以在你的Global.asax

routes.MapPageRoute("date_range", 
    "{main}/{a}/from/{fyear}/{fmonth}/{fday}/to/{tyear}/{tmonth}/{tday}", 
    "~/Default.aspx"); 

的的Application_Start使用下面的代码,并把下一码在Default.aspx的,你可以检索“一”,“date_in”的数据你的Page_Load事件和“date_out”你可能想

string _strQuery = string.Format("you are using this {6} from: {2}/{1}/{0} to: {5}/{4}/{3}", 
       Page.RouteData.Values["fyear"] as string, 
       Page.RouteData.Values["fmonth"] as string, 
       Page.RouteData.Values["fday"] as string, 
       Page.RouteData.Values["tyear"] as string, 
       Page.RouteData.Values["tmonth"] as string, 
       Page.RouteData.Values["tday"] as string, 
       Page.RouteData.Values["a"] as string); 

Response.Write(_strQuery);