.net core mvc route的注冊,激活,調(diào)用流程
mvc的入口是route,當(dāng)前請求的url匹配到合適的route之后,mvc根據(jù)route所指定的controller和action激活controller并調(diào)用action完成mvc的處理流程。下面我們看看服務(wù)器是如何調(diào)用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?}"); }); } }