Startup.cs 1.4 KB

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