mvc 路由
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "ad", url: "{controller}/{action}/sid{sid}/adid{adid}/{id}", defaults: new { controller = "Main", action = "Index", sid = UrlParameter.Optional,adid=UrlParameter.Optional,id = UrlParameter.Optional }, constraints: new { sid = @"\d+" } ); //routes.MapRoute( // name: "share", // url: "{controller}/{action}/sid{sid}/{id}", // defaults: new { controller = "Main", action = "Index", sid = UrlParameter.Optional, id = UrlParameter.Optional }, // constraints: new { sid = @"\d+" } //); routes.MapRoute( name: "share", url: "{sid}/{controller}/{action}/{id}", defaults: new { controller = "Main", action = "Index1", sid = UrlParameter.Optional, id = UrlParameter.Optional }, constraints: new { sid = @"\d+" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional } ); }
public ActionResult Index1(int sid,Guid? id) { Response.Write(RouteData.GetRequiredString("sid").ToString()); return Content(string.Format("<br/>sid={0}<br />id={1}<br />", sid, id)); }