本文整理汇总了C#中IApplicationBuilder.UseErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseErrorHandler方法的具体用法?C# IApplicationBuilder.UseErrorHandler怎么用?C# IApplicationBuilder.UseErrorHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseErrorHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IApplicationBuilder app)
{
app.UseErrorHandler();
app.UsePlainText();
app.UseJson();
if (StartupOptions.EnableDbTests)
{
app.UseSingleQueryRaw(StartupOptions.ConnectionString);
app.UseSingleQueryDapper(StartupOptions.ConnectionString);
app.UseSingleQueryEf();
app.UseMultipleQueriesRaw(StartupOptions.ConnectionString);
app.UseMultipleQueriesDapper(StartupOptions.ConnectionString);
app.UseMultipleQueriesEf();
app.UseFortunesRaw(StartupOptions.ConnectionString);
app.UseFortunesDapper(StartupOptions.ConnectionString);
app.UseFortunesEf();
var dbContext = (ApplicationDbContext)app.ApplicationServices.GetService(typeof(ApplicationDbContext));
var seeder = (ApplicationDbSeeder)app.ApplicationServices.GetService(typeof(ApplicationDbSeeder));
if (!seeder.Seed(dbContext))
{
Environment.Exit(1);
}
Console.WriteLine("Database tests enabled");
}
app.UseMvc();
app.Run(context => context.Response.WriteAsync("Try /plaintext instead"));
}
示例2: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
// Uncomment the following line to add a route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
});
}
示例3: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
// Configure the HTTP request pipeline.
// Add the console logger.
loggerfactory.AddConsole(minLevel: LogLevel.Verbose);
// Add the following to the request pipeline only in development environment.
if (env.IsEnvironment("Development"))
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
SampleData.Initialize(app.ApplicationServices);
}
示例4: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
#if DNXCORE50
.WriteTo.TextWriter(Console.Out)
#else
.WriteTo.Trace()
.WriteTo.RollingFile("log-{Date}.txt")
#endif
.CreateLogger();
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddSerilog();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
app.UseErrorHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例5: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
app.UseBrowserLink();
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
app.UseMvcWithDefaultRoute();
//Long-hand way to map the default route
//app.UseMvc(routes =>
//{
// routes.MapRoute(
// name: "default",
// template: "{controller=Home}/{action=Index}/{id?}");
//});
}
示例6: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(minLevel: LogLevel.Warning);
if (env.IsEnvironment("Development")) {
////app.UseBrowserLink();
app.UseErrorPage(new ErrorPageOptions { SourceCodeLineCount = 10 });
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
} else {
app.UseErrorHandler("/Home/Error");
}
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
if (env.IsEnvironment("Development")) {
app.UseHardCodedAuthentication();
} else {
// Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
// app.UseFacebookAuthentication();
// app.UseGoogleAuthentication();
// app.UseMicrosoftAccountAuthentication();
// app.UseTwitterAuthentication();
}
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例7: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
}
else
{
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
示例8: Configure
public void Configure(IApplicationBuilder app)
{
var password = config["password"];
if (config["RecreateDatabase"] == "true")
{
var context = app.ApplicationServices.GetService<Models.BlogDataContext>();
context.Database.EnsureDeleted();
System.Threading.Thread.Sleep(2000);
context.Database.EnsureCreated();
}
app.UseIdentity();
if (config["debug"] == "true")
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Home}/{action=Index}/{id?}"));
app.UseFileServer();
}
示例9: Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseErrorHandler(a =>
{
a.UseMiddleware<ErrorMiddleware>();
});
app.UseWelcomePage("/welcome");
app.UseRuntimeInfoPage("/runtimeinfo");
//app.UseErrorPage();
app.Run(async (context) =>
{
if (context.Request.Query.ContainsKey("throw"))
throw new AggregateException("Some funny exception, 42");
await context.Response.WriteAsync("Hello World!");
});
}
示例10: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseErrorHandler("/index.html");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add SignalR to the request pipeline.
app.UseSignalR();
// Add MVC to the request pipeline.
app.UseMvc();
app.ApplicationServices.GetRequiredService<PerformanceGenerator>();
}
示例11: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
{
// Configure the HTTP request pipeline.
// Add the console logger.
loggerfactory.AddConsole();
// Add the following to the request pipeline only in development environment.
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例12: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Serve the default file, if present.
app.UseDefaultFiles();
// Add static files to the request pipeline.
app.UseStaticFiles();
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
}
示例13: Configure
public void Configure(IApplicationBuilder app)
{
var kestrel = app.ServerFeatures[typeof(IKestrelServerInformation)] as IKestrelServerInformation;
if (kestrel != null)
{
// Using an I/O thread for every 2 logical CPUs appears to be a good ratio
kestrel.ThreadCount = Environment.ProcessorCount >> 1;
kestrel.NoDelay = true;
}
app.UseErrorHandler();
app.UsePlainText();
app.UseJson();
if (StartupOptions.EnableDbTests)
{
app.UseSingleQueryRaw(StartupOptions.ConnectionString);
app.UseSingleQueryEf();
var dbContext = (ApplicationDbContext)app.ApplicationServices.GetService(typeof(ApplicationDbContext));
var seeder = (ApplicationDbSeeder)app.ApplicationServices.GetService(typeof(ApplicationDbSeeder));
if (!seeder.Seed(dbContext))
{
Environment.Exit(1);
}
Console.WriteLine("Database tests enabled");
}
app.UseMvc();
app.Run(context => context.Response.WriteAsync("Try /plaintext instead"));
}
示例14: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseErrorHandler("App/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
// Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
// app.UseFacebookAuthentication();
// app.UseGoogleAuthentication();
// app.UseMicrosoftAccountAuthentication();
// app.UseTwitterAuthentication();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "home",
template: "home",
defaults: new { area = "app", controller = "home", action = "home" });
routes.MapRoute(
name: "dashboard",
template: "dash",
defaults: new { area = "app", controller = "home", action = "dash" });
routes.MapRoute(
name: "administration",
template: "admin",
defaults: new { area = "app", controller = "home", action = "admin" });
routes.MapRoute(
name: "default",
template: "{area}/{controller}/{action}",
defaults: new { area = "app", controller = "home", action = "index" });
});
}
示例15: Configure
public void Configure(IApplicationBuilder app)
{
var config = new Configuration();
config.AddEnvironmentVariables();
config.AddJsonFile("config.json");
config.AddJsonFile("config.dev.json", true);
config.AddUserSecrets();
var password = config.Get("password");
if (config.Get<bool>("RecreateDatabase"))
{
var context = app.ApplicationServices.GetService<Models.BlogDataContext>();
context.Database.EnsureDeleted();
System.Threading.Thread.Sleep(2000);
context.Database.EnsureCreated();
}
if (config.Get<bool>("debug"))
{
app.UseErrorPage();
app.UseRuntimeInfoPage();
}
else
{
app.UseErrorHandler("/home/error");
}
app.UseMvc(routes => routes.MapRoute(
"Default", "{controller=Home}/{action=Index}/{id?}"));
app.UseFileServer();
}