2013-03-20 44 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);