using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.EntityFrameworkCore; using DMSSample.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using DMSSample.Services; using Microsoft.Extensions.Logging; using Amazon.DatabaseMigrationService; using Amazon.Extensions.NETCore.Setup; using Microsoft.AspNetCore.Diagnostics; using Amazon.DynamoDBv2; namespace DMSSample { public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // services.Configure(options => { // options.CheckConsentNeeded = ContextBoundObject => true; // options.MinimumSameSitePolicy = SameSiteMode.None; // }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.Configure(Configuration.GetSection("AppSettings")); services.AddSingleton(Configuration); services.AddDefaultAWSOptions(Configuration.GetAWSOptions()); services.AddOptions(); services.AddEntityFrameworkSqlServer().AddDbContext(); services.AddEntityFrameworkSqlServer().AddDbContext(); services.AddScoped(); // ENABLE THE FOLLOWING 2 INSTRUCTIONS TO ENABLE DYNAMODB SESSION STATE // services.AddDistributedDynamoDbCache(options => { // options.TableName = "DMS_Session_State"; // options.IdleTimeout = new TimeSpan(0, 10, 0); // options.TtlAttribute = "TTL"; // }); // services.AddAWSService(); // ENABLE THE FOLLOWING LINE TO ENABLE IN-MEMORY SESSION STATE services.AddDistributedMemoryCache(); services.AddSession(); services.AddAWSService(ServiceLifetime.Singleton); } // 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(); if (env.IsDevelopment() && false ) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; context.Response.ContentType = "text/html"; await context.Response.WriteAsync("\r\n"); await context.Response.WriteAsync("

ERROR!



\r\n"); var exceptionHandlerPathFeature = context.Features.Get(); // exceptionHandlerPathFeature: to process the exception/logging, but do not expose error information directly to client. THE CODE BELOW IS FOR STUDY PURPOSES ONLY. await context.Response.WriteAsync("
\r\n");
                        await context.Response.WriteAsync(exceptionHandlerPathFeature?.Error.Message);
                        await context.Response.WriteAsync("
\r\n"); await context.Response.WriteAsync("

STACK



\r\n"); await context.Response.WriteAsync("
");
                        await context.Response.WriteAsync(exceptionHandlerPathFeature?.Error.StackTrace);
                        await context.Response.WriteAsync("
"); await context.Response.WriteAsync("
Home
\r\n"); await context.Response.WriteAsync("\r\n"); await context.Response.WriteAsync(new string(' ', 512)); // IE padding }); }); app.UseHsts(); } //app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseCookiePolicy(); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } }