Program.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.Extensions.Configuration;
  3. using Safeguard.EntityFramework;
  4. using System.Configuration;
  5. using System.Text;
  6. using System.Text.Encodings.Web;
  7. using System.Text.Unicode;
  8. namespace Safeguard
  9. {
  10. public class Program
  11. {
  12. public static void Main(string[] args)
  13. {
  14. var builder = WebApplication.CreateBuilder(args);
  15. // 数据库连接
  16. builder.Services.AddDbContext<Context>(
  17. opt => opt.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
  18. // Add services to the container.
  19. // asp.net core web api 输出的 json 中文被编码(乱码)的问题
  20. builder.Services.AddControllers().AddJsonOptions(options =>
  21. {
  22. options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  23. });
  24. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  25. builder.Services.AddEndpointsApiExplorer();
  26. builder.Services.AddSwaggerGen();
  27. var app = builder.Build();
  28. app.UseStaticFiles();
  29. // Configure the HTTP request pipeline.
  30. //if (app.Environment.IsDevelopment())
  31. //{
  32. // app.UseSwagger();
  33. // app.UseSwaggerUI();
  34. //}
  35. app.UseSwagger();
  36. app.UseSwaggerUI();
  37. app.UseAuthorization();
  38. app.MapControllers();
  39. app.Run();
  40. }
  41. }
  42. }