我正在使用 swagger 记录我的 web api.但是,当我运行我的项目时,它会引发错误找不到方法:'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware...".
我只遵循了 youtube 上的教程.不确定错误的原因是什么.
我的项目是 .Net Core 3.
内部类 SwaggerConfiguration{公共静态无效配置(IServiceCollection 服务){services.AddSwaggerGen(c =>{c.SwaggerDoc("v1", new Info() { Title = "Sample Portal API", Version = "1.0.0.0" });});}公共静态无效配置(IConfiguration配置,IApplicationBuilder应用程序){var swaggerOptions = new SwaggerOptions(configuration).Bind();app.UseSwagger(options =>{options.RouteTemplate = swaggerOptions.Route;});app.UseSwaggerUI(options =>{options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description);});}私有类 SwaggerOptions{IConfiguration_configuration;公共 SwaggerOptions(IConfiguration 配置){_configuration = 配置;}公共字符串路由{获取;放;}公共字符串 描述 { get;放;}公共字符串 UIEndpoint { 获取;放;}公共 SwaggerOptions 绑定(){_configuration.GetSection(nameof(SwaggerOptions)).Bind(this);返回这个;}}}这是我的创业班
public void ConfigureServices(IServiceCollection services){services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);SwaggerConfiguration.Configure(services);}公共无效配置(IApplicationBuilder 应用程序,IWebHostEnvironment 环境){如果 (env.IsDevelopment()){app.UseDeveloperExceptionPage();}SwaggerConfiguration.Configure(Configuration, app);app.UseHttpsRedirection();app.UseRouting();app.UseAuthorization();app.UseEndpoints(endpoints =>{端点.MapControllers();});}有人可以照亮,提前致谢
解决方案我可以通过点击此链接(在撰写本文时于 2019 年 8 月 20 日更新)::>
开始使用 Swashbuckle 和 ASP.NET Core
也看看他们的 GitHub 链接:
AspNetCore.Docs
I'm documenting my web api using swagger. However when I run my Project, it throws an error "Method not found: 'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware...".
I only followed the tutorials from youtube. Not sure what is the cause of error.
My project is .Net Core 3.
internal class SwaggerConfiguration { public static void Configure(IServiceCollection services) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info() { Title = "Sample Portal API", Version = "1.0.0.0" }); }); } public static void Configure(IConfiguration configuration, IApplicationBuilder app) { var swaggerOptions = new SwaggerOptions(configuration).Bind(); app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.Route; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UIEndpoint, swaggerOptions.Description); }); } private class SwaggerOptions { IConfiguration _configuration; public SwaggerOptions(IConfiguration configuration) { _configuration = configuration; } public string Route { get; set; } public string Description { get; set; } public string UIEndpoint { get; set; } public SwaggerOptions Bind() { _configuration.GetSection(nameof(SwaggerOptions)).Bind(this); return this; } } }this is my startup class
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); SwaggerConfiguration.Configure(services); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } SwaggerConfiguration.Configure(Configuration, app); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }Can someone shed a light, thanks in advance
解决方案I was able to get it going by following this link (updated 8/20/2019 as of this writing):
Get started with Swashbuckle and ASP.NET Core
Take a look at their GitHub link too:
AspNetCore.Docs
更多推荐
Swagger 和 .Net Core 3 集成
发布评论