手动搭建ASP.NET MVC5
1.创建一个空白的解决方案
2.创建一个空白的 Web Application
3.微软会非常友好的添加一大堆你可能一辈子都用不着的程序集引用。因此我们第一件事儿就是删掉他们。删到如下程度为止:
4.Nuget 安装 ASP.NET MVC 5
5.创建Global.asax
创建完成后并修改代码如下:
using System.Web.Routing; namespace MVC5.Web { public class Global : System.Web.HttpApplication { protected void Application_Start() { //注册 路由规则 RouteConfig.RegisterRoutes(RouteTable.Routes); } } }
其中RouteConfig在App_Start文件夹下,要先自己创建好,代码如下:
using System.Web.Mvc; using System.Web.Routing; namespace MVC5.Web { 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 } ); } } }
6.未完待续...