public void Configure(IApplicationBuilder app, IHostingEnvironment env, IWelcomService welcomService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage();//针对开发人员。 } else { app.UseExceptionHandler();//针对非开发人员。 } app.UseStaticFiles(); app.UseMvc(); //第一种路由方式:Conventional Route app.UseMvc(builder => { // /Home/Index ——>HomeController Index() builder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"); }); /*app.UseMvc(builder => * { * * });*/ //app.UseMvcWithDefaultRoute();//默认路由 }
public void Configure( IApplicationBuilder app, IHostingEnvironment env, IWelcomService welcomService, ILogger <Startup> logger) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } app.UseStaticFiles();//wwwroot文件夹 app.UseStaticFiles(new StaticFileOptions { RequestPath = "/node_modules", FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath + "/node_modules")), }); app.UseAuthentication(); app.UseMvc(builder => { builder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}"); }); //中间件 //app.Use(next => //{ // logger.LogInformation("Use中间件..."); // return async httpContext => // { // logger.LogInformation("中间件里判断..."); // if (httpContext.Request.Path.StartsWithSegments("/test")) // await httpContext.Response.WriteAsync("TestMiddleWare"); // else // await next(httpContext); // }; //}); //app.UseWelcomePage(new WelcomePageOptions { Path = "/welcome" }); app.UseFileServer(); //app.Run(async (context) => //{ // await context.Response.WriteAsync(welcomService.WelcomeMessage()); //}); }