|
| 1 | +using jQueryDatatableServerSideNetCore.Data; |
| 2 | +using Microsoft.AspNetCore.Builder; |
| 3 | +using Microsoft.AspNetCore.Hosting; |
| 4 | +using Microsoft.AspNetCore.Identity; |
| 5 | +using Microsoft.EntityFrameworkCore; |
| 6 | +using Microsoft.Extensions.Configuration; |
| 7 | +using Microsoft.Extensions.DependencyInjection; |
| 8 | +using Microsoft.Extensions.Hosting; |
| 9 | +using Newtonsoft.Json.Converters; |
| 10 | + |
| 11 | +namespace jQueryDatatableServerSideNetCore |
| 12 | +{ |
| 13 | + public class Startup |
| 14 | + { |
| 15 | + public Startup(IConfiguration configuration) |
| 16 | + { |
| 17 | + Configuration = configuration; |
| 18 | + } |
| 19 | + |
| 20 | + public IConfiguration Configuration { get; } |
| 21 | + |
| 22 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 23 | + public void ConfigureServices(IServiceCollection services) |
| 24 | + { |
| 25 | + services.AddDbContext<ApplicationDbContext>(options => |
| 26 | + options.UseSqlServer( |
| 27 | + Configuration.GetConnectionString("DefaultConnection"))); |
| 28 | + services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) |
| 29 | + .AddEntityFrameworkStores<ApplicationDbContext>(); |
| 30 | + |
| 31 | + services.AddControllersWithViews() |
| 32 | + .AddNewtonsoftJson(options => |
| 33 | + { |
| 34 | + options.SerializerSettings.Converters.Add(new StringEnumConverter()); |
| 35 | + }); |
| 36 | + |
| 37 | + services.AddRazorPages(); |
| 38 | + } |
| 39 | + |
| 40 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 41 | + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
| 42 | + { |
| 43 | + if (env.IsDevelopment()) |
| 44 | + { |
| 45 | + app.UseDeveloperExceptionPage(); |
| 46 | + app.UseDatabaseErrorPage(); |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + app.UseExceptionHandler("/Home/Error"); |
| 51 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 52 | + app.UseHsts(); |
| 53 | + } |
| 54 | + app.UseHttpsRedirection(); |
| 55 | + app.UseStaticFiles(); |
| 56 | + |
| 57 | + app.UseRouting(); |
| 58 | + |
| 59 | + app.UseAuthentication(); |
| 60 | + app.UseAuthorization(); |
| 61 | + |
| 62 | + app.UseEndpoints(endpoints => |
| 63 | + { |
| 64 | + endpoints.MapControllerRoute( |
| 65 | + name: "default", |
| 66 | + pattern: "{controller=Home}/{action=Index}/{id?}"); |
| 67 | + endpoints.MapRazorPages(); |
| 68 | + }); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments