Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ****************************** Program.cs
- using Microsoft.AspNetCore;
- using Microsoft.AspNetCore.Hosting;
- namespace NCHInternalWebSite
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- //var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
- //XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
- CreateWebHostBuilder(args).Build().Run();
- }
- // -------------- Exception thrown here
- public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup<Startup>();
- }
- }
- ****************************** Startup.cs
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- namespace NCHInternalWebSite
- {
- public class Startup
- {
- private readonly ILogger _logger;
- public Startup(IConfiguration configuration, ILogger<Startup> logger)
- {
- Configuration = configuration;
- _logger = logger;
- _logger.LogInformation("Starting web application . . .");
- }
- 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<CookiePolicyOptions>(options =>
- {
- // This lambda determines whether user consent for non-essential cookies is needed for a given request.
- options.CheckConsentNeeded = context => true;
- options.MinimumSameSitePolicy = SameSiteMode.None;
- });
- services.AddLogging(logging =>
- {
- logging.AddConsole();
- logging.AddDebug();
- });
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
- _logger.LogInformation("Configured Services . . .");
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggingBuilder loggingBuilder)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
- app.UseHsts();
- }
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseCookiePolicy();
- // TODO: Configure logging via dependency injection?
- //loggingBuilder.AddLog4Net();
- loggingBuilder.AddDebug();
- loggingBuilder.AddConsole();
- // TODO: Is CORS worth it? Cross site forgery anti token will tank .net core applications without a policy in place first
- // https://weblog.west-wind.com/posts/2016/sep/26/aspnet-core-and-cors-gotchas
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Login}/{action=Index}/");
- });
- _logger.LogInformation("Configuring . . .");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement