最近在研究搜索引擎优化(SEO),使用工具分析了网站的发现ASP.NET MVC的网站的URL格式:Http://www.mikel.cn/Home/Index,该工具抓取不了?于是想到伪静态成:Http://www.mikel.cn/Home/Index.html,于是修改了Global.asax如下(注意:一定要将Default路由配置放在最后,否则伪静态的代码不能显示,因为MVC是从上到下遍历routeDictionary的,遇到匹配的url就行解析):
public class GlobalApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Html", // Route name "{controller}/{action}.html", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } }