asy*_*ait 4 asp.net-mvc routing static
我知道这可能很傻,但是希望大师为我澄清一下......为什么这个方法被定义为静态..
public class MvcApplication : System.Web.HttpApplication
{
/* Why this method is declared as static? */
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
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);
}
}
Run Code Online (Sandbox Code Playgroud)
它的静态因为它不需要是与类的实例直接相关的方法,而是一个可以在静态上下文中使用的方法.
换句话说,它只影响参数"routes",它不使用任何类字段或成员,因此它是静态的.