Startup.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.HttpsPolicy;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Serialization;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Threading.Tasks;
  15. using XYY.Authentication.Standard;
  16. using XYY.Service.Standard.RegionService;
  17. namespace XYY.Api.Channel
  18. {
  19. public class Startup
  20. {
  21. public Startup(IConfiguration configuration)
  22. {
  23. Configuration = configuration;
  24. }
  25. public IConfiguration Configuration { get; }
  26. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  27. // This method gets called by the runtime. Use this method to add services to the container.
  28. public void ConfigureServices(IServiceCollection services)
  29. {
  30. services.AddXYYService(new ServiceOption
  31. {
  32. USEDBTransferAsMVC = true,
  33. CacheType = DistributedCacheType.Memory,
  34. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey]
  35. }, Configuration);
  36. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  37. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  38. services.AddControllers().AddNewtonsoftJson(options =>
  39. {
  40. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  41. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  42. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  43. });
  44. }
  45. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  46. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  47. {
  48. if (env.IsDevelopment())
  49. {
  50. app.UseDeveloperExceptionPage();
  51. }
  52. app.UseStatusCodePages();
  53. app.UseRouting();
  54. app.UseCors(MyAllowSpecificOrigins);
  55. app.UseEndpoints(endpoints =>
  56. {
  57. endpoints.MapControllers();
  58. });
  59. }
  60. }
  61. }