c#代碼小集
一、字符串[Uri]轉換出RouteData
private RouteData UriToRouteData(Uri uri) { var query = uri.Query; if (uri.Query.Length > 0) { query = query.Substring(1, uri.Query.Length - 1); } var request = new HttpRequest("", uri.AbsoluteUri, query); var routeData= Url.RouteCollection.GetRouteData(new HttpContextWrapper(new HttpContext( request, new HttpResponse(null)))); if (request.QueryString.Count > 0 && routeData != null) { foreach (string key in request.QueryString.Keys) { routeData.Values.Add(key, request.QueryString[key]); } } return routeData; } //調用 //RouteData routeData = UriToRouteData(Request.UrlReferrer);