通过设置路由,可以灵活的显示地址内容。它会自动转换为想要的控制器和方法中去。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace UrlsAndRoutes
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
//routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapRoute(
// name: "Default",
// url: "{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
//);
//routes.MapRoute("MyRoute", "{controller}/{action}",
// new { action = "Index" });
//routes.MapRoute("ShopSchema", "Shop/{action}",
// new { controller = "Home" });
//routes.MapRoute("", "X{controller}/{action}",
// new { controller = "Home", action = "Index" });
//routes.MapRoute("MyRoute", "{controller}/{action}",
// new { controller = "Home", action = "Index" });
//routes.MapRoute("", "Public/{controller}/{action}",
// new { controller = "Home", action = "Index" });
//routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
// new
// {
// controller = "Home",
// action = "Index",
// id = "DefaultId"
// });
//routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
// new
// {
// controller = "Home",
// action = "Index",
// id = UrlParameter.Optional
// });
routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
}
}
}
还有很多精髓的用法,碉堡了,.Net。