.net core mvc route的注冊,激活,調用流程
mvc的入口是route,當前請求的url匹配到合適的route之后,mvc根據route所指定的controller和action激活controller并調用action完成mvc的處理流程。下面我們看看服務器是如何調用route的。
core mvc startup基本代碼。重點在AddMvc和UseMvc
public class Startup{ public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } }