firts commit
This commit is contained in:
97
KART_API/Program.cs
Normal file
97
KART_API/Program.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using SwaggerFilter.Filters;
|
||||
using System.Reflection;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
var log4netRepository = log4net.LogManager.GetRepository(Assembly.GetEntryAssembly());
|
||||
log4net.Config.XmlConfigurator.Configure(log4netRepository, new FileInfo("log4net.config"));
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var services = builder.Services;
|
||||
|
||||
// Add services to the container.
|
||||
services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
services.AddEndpointsApiExplorer();
|
||||
|
||||
//HttpContext <20><><EFBFBD><EFBFBD>
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
services.AddSwaggerGen(gen =>
|
||||
{
|
||||
gen.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
|
||||
{
|
||||
Version = "v1",
|
||||
Title = "KART API NET 8.0",
|
||||
Description = "KART API NET 8.0"
|
||||
});
|
||||
|
||||
gen.AddSecurityDefinition("token", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "Custom header for token",
|
||||
Name = "token",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
});
|
||||
|
||||
gen.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "token"
|
||||
},
|
||||
Name = "token",
|
||||
In = ParameterLocation.Header,
|
||||
},
|
||||
new List<string>()
|
||||
}
|
||||
});
|
||||
|
||||
gen.DocumentFilter<CustomSwaggerFilter>();
|
||||
gen.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
|
||||
});
|
||||
|
||||
services.Configure<WebEncoderOptions>(options =>
|
||||
{
|
||||
options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All); // <20>ѱ<EFBFBD><D1B1><EFBFBD> <20><><EFBFBD>ڵ<EFBFBD><DAB5>Ǵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ذ<EFBFBD>
|
||||
});
|
||||
|
||||
services.AddCors(options => {
|
||||
options.AddDefaultPolicy(policy =>
|
||||
{
|
||||
policy.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyOrigin()
|
||||
.WithExposedHeaders(new string[] { "Content-Disposition" });
|
||||
});
|
||||
});
|
||||
|
||||
//Server Path<74><68><EFBFBD><EFBFBD>
|
||||
AppDomain.CurrentDomain.SetData("ContentRootPath", Environment.CurrentDirectory);
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Showing API V1");
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user