123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<Context>(
- 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();
- }
- }
- }
|