Startup.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. using XYY.Service.Standard.RegionService;
  14. using Newtonsoft.Json;
  15. using Newtonsoft.Json.Serialization;
  16. using XYY.Authentication.Standard;
  17. using System.Text;
  18. namespace XYY.API.SINO.Order
  19. {
  20. public class Startup
  21. {
  22. public Startup(IConfiguration configuration)
  23. {
  24. Configuration = configuration;
  25. }
  26. public IConfiguration Configuration { get; }
  27. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  28. // This method gets called by the runtime. Use this method to add services to the container.
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddXYYService(new ServiceOption
  32. {
  33. USEDBTransferAsMVC = true,
  34. CacheType = DistributedCacheType.Memory,
  35. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey]
  36. }, Configuration);
  37. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  38. policy.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod()));
  39. services.AddControllers().AddNewtonsoftJson(options =>
  40. {
  41. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  42. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  43. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  44. });
  45. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  46. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  47. );
  48. services.AddAuthorization();
  49. }
  50. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  51. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  52. {
  53. //×¢²áGB2312
  54. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  55. if (env.IsDevelopment())
  56. {
  57. app.UseDeveloperExceptionPage();
  58. }
  59. app.UseStatusCodePages();
  60. app.UseRouting();
  61. app.UseCors(MyAllowSpecificOrigins);
  62. app.UseAuthentication();
  63. app.UseEndpoints(endpoints =>
  64. {
  65. endpoints.MapControllers();
  66. });
  67. }
  68. }
  69. }