Startup.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Configuration;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. namespace Masuit.Tools.Core.Test.AspNetCore
  7. {
  8. public class Startup
  9. {
  10. public Startup(IConfiguration configuration)
  11. {
  12. Configuration = configuration;
  13. }
  14. public IConfiguration Configuration { get; }
  15. // This method gets called by the runtime. Use this method to add services to the container.
  16. public void ConfigureServices(IServiceCollection services)
  17. {
  18. services.AddMvc();
  19. }
  20. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  21. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  22. {
  23. if (env.IsDevelopment())
  24. {
  25. app.UseDeveloperExceptionPage();
  26. }
  27. app.UseRouting(); // 放在 UseStaticFiles 之后
  28. app.UseEndpoints(endpoints =>
  29. {
  30. endpoints.MapControllers(); // 属性路由
  31. endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); // 默认路由
  32. });
  33. }
  34. }
  35. }