54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DatabaseErrorPageSample
|
|
{
|
|
public class Startup
|
|
{
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddEntityFramework()
|
|
.AddSqlServer()
|
|
.AddDbContext<MyContext>(options => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=DatabaseErrorPageSample;Trusted_Connection=True;"));
|
|
}
|
|
|
|
public void Configure(IApplicationBuilder app)
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseDatabaseErrorPage();
|
|
app.Run(context =>
|
|
{
|
|
context.RequestServices.GetService<MyContext>().Blog.FirstOrDefault();
|
|
return Task.FromResult(0);
|
|
});
|
|
}
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
var host = new WebHostBuilder()
|
|
.UseDefaultConfiguration(args)
|
|
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
|
|
.UseIISPlatformHandlerUrl()
|
|
.UseStartup<Startup>()
|
|
.Build();
|
|
|
|
host.Run();
|
|
}
|
|
}
|
|
|
|
public class MyContext : DbContext
|
|
{
|
|
public DbSet<Blog> Blog { get; set; }
|
|
}
|
|
|
|
public class Blog
|
|
{
|
|
public int BlogId { get; set; }
|
|
public string Url { get; set; }
|
|
}
|
|
}
|