/// <summary> /// 使用ApiExplorer User Interface中间件以生成UI /// </summary> /// <param name="applicationBuilder"></param> /// <param name="setupAction">配置</param> /// <returns></returns> public static IApplicationBuilder UseApiExplorerUI( this IApplicationBuilder applicationBuilder, Action <ApiExplorerUIOptions> setupAction = null) { var options = new ApiExplorerUIOptions(); setupAction?.Invoke(options); applicationBuilder.UseMiddleware <ApiExplorerUIRedirectMiddleware>(options.BaseRoute, options.IndexPath); applicationBuilder.UseMiddleware <ApiExplorerUIInitJsonMIddleware>(options); var fileServerOptions = new FileServerOptions { RequestPath = $"/{options.BaseRoute}", EnableDefaultFiles = false, FileProvider = new EmbeddedFileProvider(typeof(Embedded).GetTypeInfo().Assembly, Embedded.FileNamespace), }; fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider(); applicationBuilder.UseFileServer(fileServerOptions); return(applicationBuilder); }
public static IApplicationBuilder UseSwaggerUi( this IApplicationBuilder app, Action <SwaggerUiOptions> setupAction) { var options = new SwaggerUiOptions(); setupAction?.Invoke(options); // Serve static assets (CSS, JavaScript etc.) via static file server var fileServerOptions = new FileServerOptions { RequestPath = $"/{options.RoutePrefix}", FileProvider = new EmbeddedFileProvider(typeof(SwaggerUiBuilderExtensions).GetTypeInfo().Assembly, "Swashbuckle.AspNetCore.SwaggerUi.bower_components.swagger_ui.dist") }; fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileExtensionContentTypeProvider(); app.UseFileServer(fileServerOptions); // Serve the index.html page at /{options.RoutePrefix}/ via middleware app.UseMiddleware <SwaggerUiMiddleware>(options); return(app); }
/// <summary> /// Enable all static file middleware with the given options /// </summary> /// <param name="app"></param> /// <param name="options"></param> /// <returns></returns> public static IApplicationBuilder UseFileServer(this IApplicationBuilder app, FileServerOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.EnableDefaultFiles) { app.UseDefaultFiles(options.DefaultFilesOptions); } if (options.EnableDirectoryBrowsing) { app.UseDirectoryBrowser(options.DirectoryBrowserOptions); } return(app.UseStaticFiles(options.StaticFileOptions)); }