Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Swagger是WebAPI(路由)的基本URL的一部分_C#_Asp.net_.net_Swagger_Swashbuckle - Fatal编程技术网

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

C# Swagger是WebAPI(路由)的基本URL的一部分,c#,asp.net,.net,swagger,swashbuckle,C#,Asp.net,.net,Swagger,Swashbuckle,所以我完全不知道发生了什么,但突然间,Swagger成为了我端点URL的一部分,这意味着它不再是URL.com/api/Values,而是URL.com/Swagger/api/Values。我不确定这是怎么发生的,我已经到处寻找关于修改基本URL等的信息,但我确信我只是在某个地方犯了一个小错误 配置() 配置服务() { services.AddDbContext(选项=> options.UseSqlServer( GetConnectionString(“DefaultConnection

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

配置()

配置服务()

{
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
//在范围内注册整洁
services.addScope();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(选项=>
{
options.TokenValidationParameters=新的TokenValidationParameters
{
validateisuer=true,
ValidateAudience=true,
ValidateLifetime=true,
ValidateSuersigningKey=true,
ValidIssuer=配置[“Jwt:Issuer”],
Validudience=配置[“Jwt:Issuer”],
IssuerSigningKey=new-SymmetricSecurityKey(Encoding.UTF8.GetBytes(配置[“Jwt:Key”]))
};
});
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c=>
{
c、 AddSecurityDefinition(“载体”),新的OpenApiSecurityScheme
{
描述=
“使用承载方案的JWT授权头。\r\n\r\n输入'Bearer'[space],然后在下面的文本输入中输入您的令牌。\r\n\r\n例如:\“Bearer 12345abcdef\”,
Name=“授权”,
In=参数位置.Header,
类型=SecuritySchemeType.ApiKey,
Scheme=“持票人”
});
}

检查你的launchSettings.json URL可能有问题

你是否尝试为你的控制器设置路由属性?如果你确实有路由属性,你是指查看swagger页面时的实际端点还是端点注释?@Farshad感谢你的回复。我为所有控制器设置的路由是:[route](“api/[controller]/[action]”)是的,我的意思是我以前拥有的端点localhost:4400/api/Values现在是localhost:4400/Swagger/api/Values谢谢。您是否尝试过将
UseSwagger
UseSwaggerUI
移动到
UseMvc
之后?您好!感谢您花时间回复。以下是我的启动设置:(我已经提供了swagger/swagger,因为/swagger将返回404)。“$schema”:“,”profiles”:{“IIS Express”:{“commandName”:“IISExpress”,“launchBrowser”:true,“launchUrl”:“,”environmentVariables:{“ASPNETCORE_环境”:“Development”}},`Change“launchUrl”:“localhost:44393/swagger/index.html”到“localhost:44393/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. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Type = SecuritySchemeType.ApiKey,
                    Scheme = "Bearer"
                });
}