Startup.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. /*
  12. Scaffold-DbContext "Server=.;database=TakeOut;uid=sa;pwd=sa" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
  13. * */
  14. namespace FGCS.Core
  15. {
  16. public class Startup
  17. {
  18. public Startup(IConfiguration configuration)
  19. {
  20. Configuration = configuration;
  21. }
  22. public IConfiguration Configuration { get; }
  23. // This method gets called by the runtime. Use this method to add services to the container.
  24. public void ConfigureServices(IServiceCollection services)
  25. {
  26. services.AddMvc();
  27. //跨域请求
  28. services.AddCors(a =>
  29. {
  30. a.AddPolicy("to", policy =>
  31. {
  32. policy.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod().AllowCredentials();
  33. });
  34. });
  35. }
  36. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  37. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  38. {
  39. if (env.IsDevelopment())
  40. {
  41. app.UseDeveloperExceptionPage();
  42. }
  43. app.UseCors("to");
  44. app.UseMvc();
  45. }
  46. }
  47. }