server/aspnetapp/Program.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using aspnetapp;
using aspnetapp.Helper;
using aspnetapp.Middlewares;
using aspnetapp.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
//builder.Services.AddControllers();
//builder.Services.AddRazorPages();
builder.Services.AddMvc(options =>
{
    //options.Filters.Add<ValidateModelAttribute>();
    options.Filters.Add<ApiResultFilterAttribute>();
});

builder.Services.AddDbContext<CounterContext>(ServiceLifetime.Transient, ServiceLifetime.Transient);
builder.Services.AddSingleton<IProductService>();

builder.Services.AddSession();

#region 添加swagger注释
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
#endregion

var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
}
app.UseExceptionHandler("/Error");

app.UseSession();

app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

// 注册检测是否登录系统中间件
app.UseTokenCheck();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Login}/{action=Login}/{id?}");

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.EnablePersistAuthorization();
});

using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<CounterContext>();
后面还有 4 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。