"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
what about outside of ApiController? is there anything that can be injected into a class?
Here is a sample,
HttpControllerContext cc = new HttpControllerContext();
var routes = new HttpRouteCollection("/");
IHttpRoute route = routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
cc.Configuration = new HttpConfiguration(routes);
cc.RouteData = new HttpRouteData(route, new HttpRouteValueDictionary(new { controller = "MyA", id = "123" }));
cc.Configuration = new HttpConfiguration(routes);
var url = cc.Url;
url.ControllerContext.Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:1962/api/MyA/123");
var ll = url.Route("DefaultApi", null);
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by imran_ku07 on May 22, 2012 05:14 PM
eatdoku
0 Points
2 Posts
generate url for a resource
May 16, 2012 06:54 PM|LINK
how to generate the url given a resource entity?
url
imran_ku07
All-Star
45864 Points
7713 Posts
MVP
Re: generate url for a resource
May 20, 2012 03:49 PM|LINK
Use Url.Route method
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
bloodhard
Member
28 Points
19 Posts
Re: generate url for a resource
May 20, 2012 09:33 PM|LINK
what about outside of ApiController? is there anything that can be injected into a class?
imran_ku07
All-Star
45864 Points
7713 Posts
MVP
Re: generate url for a resource
May 21, 2012 06:13 PM|LINK
Here is a sample,
HttpControllerContext cc = new HttpControllerContext(); var routes = new HttpRouteCollection("/"); IHttpRoute route = routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); cc.Configuration = new HttpConfiguration(routes); cc.RouteData = new HttpRouteData(route, new HttpRouteValueDictionary(new { controller = "MyA", id = "123" })); cc.Configuration = new HttpConfiguration(routes); var url = cc.Url; url.ControllerContext.Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:1962/api/MyA/123"); var ll = url.Route("DefaultApi", null);Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD