doo*_*man 6 c# iis swagger swashbuckle asp.net-core
在遵循此示例文档后,我正在尝试弄清楚如何使用 Swagger (SwashBuckle) 发布 .net core 3 API 。所以它可以在本地运行,当我按 F5 IIS Express 时,会在下面启动该网站http://localhost:8033/index.html
这是startup.cs中的配置代码:
\npublic void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)\n {\n if (env.IsDevelopment())\n {\n app.UseDeveloperExceptionPage();\n }\n\n app.UseRouting();\n\n app.UseAuthorization();\n\n app.UseEndpoints(endpoints =>\n {\n endpoints.MapControllers();\n });\n\n app.UseStaticFiles(new StaticFileOptions\n {\n FileProvider = new PhysicalFileProvider(env.ContentRootPath),\n RequestPath = new PathString("")\n });\n\n app.UseSwagger();\n app.UseSwaggerUI(c =>\n {\n c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");\n c.DocumentTitle = "TestAPI";\n c.DocExpansion(DocExpansion.None);\n c.RoutePrefix = string.Empty; \n }); \n }\nRun Code Online (Sandbox Code Playgroud)\n接下来,我将 API 发布到本地文件夹,并将文件复制到服务器上的 IIS 文件夹。如果我打开服务器 API 域,我会得到一个page can\xe2\x80\x99t be found. 我应该使用哪个地址来打开服务器上的 swagger UI?配置中是否缺少某些内容?
你的设置没有问题Swagger。请不要忘记配置生成Swagger器以及注释路径Swagger JSON的注释路径。
public void ConfigureServices(IServiceCollection services)\n {\n services.AddControllers();\n services.AddSwaggerGen(c =>\n {\n c.SwaggerDoc("v1", new OpenApiInfo\n {\n Version = "v1",\n Title = "ToDo API",\n Description = "A simple example ASP.NET Core Web API",\n TermsOfService = new Uri("https://example.com/terms"),\n Contact = new OpenApiContact\n {\n Name = "Shayne Boyer",\n Email = string.Empty,\n Url = new Uri("https://twitter.com/spboyer"),\n },\n License = new OpenApiLicense\n {\n Name = "Use under LICX",\n Url = new Uri("https://example.com/license"),\n }\n });\n // Set the comments path for the Swagger JSON and UI.\n var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";\n var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);\n c.IncludeXmlComments(xmlPath);\n });\n }\nRun Code Online (Sandbox Code Playgroud)\n此外,请确保服务器已在服务器端安装了Asp.net core托管包。
\n https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.6-windows-hosting-bundle-installer
\n如果有什么我可以做的,请随时告诉我帮助。
| 归档时间: |
|
| 查看次数: |
28363 次 |
| 最近记录: |