Startup.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.Net;
  15. using System.Threading.Tasks;
  16. using XYY.Authentication.Standard;
  17. using XYY.Core.Standard.ApiClient;
  18. using XYY.Core.Standard.Data.Infrastructure;
  19. using XYY.Data.Standard.Tasks;
  20. using XYY.Service.Standard.RegionService;
  21. using XYY.TaskTrack.Standard;
  22. namespace XYY.Api.Order
  23. {
  24. public class Startup
  25. {
  26. public Startup(IConfiguration configuration)
  27. {
  28. Configuration = configuration;
  29. }
  30. public IConfiguration Configuration { get; }
  31. readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";//Ãû×ÖËæ±ãÆð
  32. // This method gets called by the runtime. Use this method to add services to the container.
  33. public void ConfigureServices(IServiceCollection services)
  34. {
  35. services.AddXYYService(new ServiceOption
  36. {
  37. USEDBTransferAsMVC = true,
  38. CacheType = DistributedCacheType.Memory,
  39. SqlServiceConnection = Configuration[DefaultConfig.SqlServiceConnectionKey],
  40. UseRabbit = true,
  41. //UseFiddler=true,
  42. }, Configuration);
  43. services.ConfigAspectCore("BoxService");
  44. services.AddCors(option => option.AddPolicy(MyAllowSpecificOrigins, policy =>
  45. policy.AllowAnyHeader().AllowAnyOrigin().WithMethods("GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS")));
  46. services.AddControllers().AddNewtonsoftJson(options =>
  47. {
  48. options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
  49. options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  50. options.SerializerSettings.ContractResolver = new DefaultContractResolver();
  51. });
  52. services.AddAuthentication(BasicAuthenticationScheme.DefaultScheme)
  53. .AddScheme<BasicAuthenticationOption, BasicAuthenticationHandler>(BasicAuthenticationScheme.DefaultScheme, null
  54. );
  55. //ºöÂÔÖ¤Êé´íÎó
  56. ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
  57. {
  58. // local dev, just approve all certs
  59. return true;
  60. };
  61. }
  62. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  63. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  64. {
  65. if (env.IsDevelopment())
  66. {
  67. app.UseDeveloperExceptionPage();
  68. }
  69. app.UseStatusCodePages();
  70. app.UseRouting();
  71. app.UseCors(MyAllowSpecificOrigins);
  72. app.UseBasicAuthentication();
  73. app.UseAuthentication();
  74. app.UseAuthorization();
  75. app.UseWebSockets();
  76. app.UseEndpoints(endpoints =>
  77. {
  78. endpoints.MapControllers();
  79. });
  80. }
  81. }
  82. }