本文整理汇总了C#中IApplicationBuilder.UseSwaggerGen方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseSwaggerGen方法的具体用法?C# IApplicationBuilder.UseSwaggerGen怎么用?C# IApplicationBuilder.UseSwaggerGen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseSwaggerGen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDefaultConfiguration();
app.UseStaticFiles();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例2: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
// Configure the HTTP request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseSwaggerGen();
app.UseSwaggerUi();
// TOOD: Figure out oauth middleware to validate token
//app.UseOAuthBearerAuthentication(opts =>
//{
//});
}
示例3: Configure
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
/// <param name="loggerFactory"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var log = loggerFactory.CreateLogger<Startup>();
try
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseDeveloperExceptionPage();
app.UseIISPlatformHandler();
CheckAuthorization(app);
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.UseMvc();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
catch (Exception ex)
{
app.Run(
async context => {
log.LogError($"{ex.Message}");
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(ex.Message).ConfigureAwait(false);
await context.Response.WriteAsync(ex.StackTrace).ConfigureAwait(false);
});
}
}
示例4: Configure
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
app.UseSwaggerGen();
app.UseSwaggerUi();
SampleData.Initialize(app.ApplicationServices);
}
示例5: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
app.UseMvcWithDefaultRoute();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例6: Configure
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseSwaggerGen();
app.UseSwaggerUi();
app.UseMvcWithDefaultRoute();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
示例7: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例8: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例9: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//TODO: Add OAuth
app.Map("/health", subApp =>
{
subApp.Use(async (context, next) =>
{
IEnumerable<Type> healthTypes =
AppDomain
.CurrentDomain
.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => typeof(IHealth).IsAssignableFrom(type)
&& type.IsAbstract == false
&& type.IsInterface == false
&& type.IsGenericTypeDefinition == false);
var servicesHealth = new Dictionary<string, string>();
foreach (var healthType in healthTypes)
{
var healthService = (IHealth)Activator.CreateInstance(healthType);
var serviceHealth = await healthService.Check();
servicesHealth.Add(healthType.ToString(), serviceHealth);
}
var jsonResponse = JsonConvert.SerializeObject(servicesHealth, Formatting.Indented);
await context.Response.WriteAsync(jsonResponse);
});
});
app.UseSwaggerGen();
app.UseSwaggerUi();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例10: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler();
// Configure the HTTP request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseDeveloperExceptionPage();
app.UseMvc();
// Add the following route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例11: Configure
public void Configure(IApplicationBuilder app)
{
// Use IIS platform handle to run ASP.NET in IIS
app.UseIISPlatformHandler();
// Use file server to serve static files
app.UseDefaultFiles();
app.UseFileServer();
// Use AI request telemetry
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
// Add middlewares (CORS and MVC)
app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
app.UseMvc();
// Configure swagger. For more details see e.g.
// http://damienbod.com/2015/12/13/asp-net-5-mvc-6-api-documentation-using-swagger/
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例12: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
//loggerFactory.AddDebug();
// ES6 Imports always pull from a .js file however signalr doesn't support the call with an extensions so remap it.
app.Rewrite("/signalr/hubs.js", "/signalr/hubs");
//app.UseSignalR();
app.UseStaticFiles();
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例13: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
app.UseCors(builder =>
{
builder
.WithMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.AllowAnyHeader()
.AllowAnyOrigin();
});
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Cookie";
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = false;
});
app.UseMvc();
app.UseSwaggerUi();
app.UseSwaggerGen();
}
示例14: Configure
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
var authLogger = loggerFactory.CreateLogger("Auth");
var settings = app.ApplicationServices.GetService<IOptions<AuthSettings>>();
app.UseJwtBearerAuthentication(options =>
{
options.Audience = settings.Value.ClientId;
options.Authority = $"https://{settings.Value.Domain}/{settings.Value.TennantId}/{settings.Value.Version}";
options.Events = new JwtBearerEvents
{
OnAuthenticationFailed = context =>
{
authLogger.LogError("Authentication failed.", context.Exception);
return Task.FromResult(0);
},
OnValidatedToken = context =>
{
var claimsIdentity = context.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
if (claimsIdentity == null) return null; // ??
claimsIdentity.AddClaim(new Claim("id_token",
context.Request.Headers["Authorization"][0].Substring(context.AuthenticationTicket.AuthenticationScheme.Length + 1)));
// OPTIONAL: you can read/modify the claims that are populated based on the JWT
claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, claimsIdentity.FindFirst("name").Value));
claimsIdentity.AddClaim(new Claim(ClaimTypes.GivenName, claimsIdentity.FindFirst("preferred_username").Value));
return Task.FromResult(0);
}
};
});
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
}
catch { }
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseApplicationInsightsExceptionTelemetry();
app.UseStaticFiles();
//app.UseIdentity();
// To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwaggerGen();
app.UseSwaggerUi();
}
示例15: Configure
public void Configure(
IApplicationBuilder app
, IHostingEnvironment env
, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
//app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage(o => o.EnableAll());
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseExceptionHandler("/Home/Error");
}
// Add the platform handler to the request pipeline.
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
//app.UseCookieAuthentication(options =>
//{
// //options.AutomaticAuthenticate = true;
// options.AccessDeniedPath = new PathString("/Account/AccessDenied");
// options.LoginPath = new PathString("/Account/Login");
// options.LogoutPath = new PathString("/Account/Logout");
//});
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute("subarearoute", "{area:exists}/{subarea:exists}/{controller=Home}/{action=Index}");
routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}");
routes.MapRoute("controllerActionRoute", "{controller=Home}/{action=Index}");
});
app.UseSwaggerGen();
app.UseSwaggerUi();
}