Swagger是WebAPI(路由)的基本URL的一部分



所以我完全不知道发生了什么,但Swagger突然成为了我的端点URL的一部分,这意味着它不再是URL.com/api/Values,而是URL.com/Swagger/api/Values。我不确定这是怎么发生的,我到处都找过关于修改基本URL等的信息,但我确信我只是在某个地方犯了一个小错误。

配置((

{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("./v1/swagger.json", "LA NOSA - FE API");
});
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseMvc();
}

配置服务((

{
services.AddDbContext<DataContext.AppContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
//Register dapper in scope    
services.AddScoped<IDapper, DapperManager>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
});
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c =>
{
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. rnrn Enter 'Bearer' [space] and then your token in the text input below.rnrnExample: "Bearer 12345abcdef"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
}

检查您的launchSettings.json是否存在URL 问题

最新更新