安装 IIS
下载需要的 net 版本安装
前往
.net core WebApi 项目打包
Program.cs
var builder = WebApplication.CreateBuilder(args);
// 输出
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null;
options.JsonSerializerOptions.WriteIndented = true;
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// 添加CORS服务,配置跨域
builder.Services.AddCors(options =>
{
options.AddPolicy("MyCorsPolicy", builder =>
{
builder.WithOrigins("*")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
// 将 app.Environment.IsDevelopment() 判断去掉,部署之后也显示文档
app.UseSwagger();
app.UseSwaggerUI();
// 应用CORS中间件和策略
app.UseCors("MyCorsPolicy");
app.UseAuthorization();
app.MapControllers();
app.Run();
发布的文件路径
配置 IIS