I wrote a route:
routes.MapRoute(
name: "LoadDefaultPage",
url: "Load",
defaults: new { controller = "Load", action = "Index" }
);
and it works fine for http://localhost/Load . But I need to do the same action for http://localhost/Load/bla , http://localhost/Load/bla/bla/ , http://localhost/Load/bla/bla/bla etc. How to describe it?
Solved it using this code (thanks for Stephen Muecke):
routes.MapRoute(
name: "LoadDefaultPage",
url: "Load/{*tmp}",
defaults: new { controller = "Load", action = "Index" }
);
You can create Controllers with different Routprefixes. eg
[RoutePrefix("Load")]
public class LoadController : ApiController
{
}
[RoutePrefix("Load/bla")]
public class LoadBlaController : ApiController
{
}
Or if you want http://localhost/Load/bla to be a Method use:
[RoutePrefix("Load")]
public class LoadController : ApiController
{
[HttpGET, Route("bla")]
public string Bla()
{
return "bla";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.