Global.asax:
void Application_Start(object sender, EventArgs e)
{
public class Global : HttpApplication
{
GlobalConfiguration.Configure(config =>
{
config.MapHttpAttributeRoutes();
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}");
});
}}
例如,我得到这个网址:
我想要的是什么(在图书实例“ lawbook”的名称后面附加:):
Global.asax:
在Global:HttpApplication
内部
//add this
public RouteValueDictionary SetRouteValueDefault(string name, string value = "")
{
return new RouteValueDictionary { { name, value } };
}
public void Register(RouteCollection routes)
{
routes.MapPageRoute("author", "books/{id}/{name}", "~/Books.aspx", false, SetRouteValueDefault("name"));
}
在Application_Start()
内部:
//add this
Register(RouteTable.Routes);
您现在可以根据需要组合实例的url
<a href="/books/book.id/book.name"></a>
信用:Ali Kleit