using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Safeguard.EntityFramework; using System.Configuration; using System.Text; using System.Text.Encodings.Web; using System.Text.Unicode; namespace Safeguard { public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // 数据库连接 builder.Services.AddDbContext( opt => opt.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); // Add services to the container. // asp.net core web api 输出的 json 中文被编码(乱码)的问题 builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); }); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseStaticFiles(); // Configure the HTTP request pipeline. //if (app.Environment.IsDevelopment()) //{ // app.UseSwagger(); // app.UseSwaggerUI(); //} app.UseSwagger(); app.UseSwaggerUI(); app.UseAuthorization(); app.MapControllers(); app.Run(); } } }