Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Logging;
  10. using StarLegacy.Web.Code.Utils;
  11. using System.IO;
  12. using Microsoft.AspNetCore.Authentication.Cookies;
  13.  
  14. namespace StarLegacy.Web
  15. {
  16. public class Startup
  17. {
  18. public Startup(IHostingEnvironment env)
  19. {
  20. var builder = new ConfigurationBuilder()
  21. .SetBasePath(env.ContentRootPath)
  22. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  23. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  24. .AddEnvironmentVariables();
  25. Configuration = builder.Build();
  26. try
  27. {
  28. DBUtils.Init();
  29. }
  30. catch (Exception exception)
  31. {
  32. File.WriteAllText("startuperror.txt", exception.ToString());
  33. Console.Error.WriteLine(exception);
  34. }
  35. }
  36.  
  37. public IConfigurationRoot Configuration { get; }
  38.  
  39. // This method gets called by the runtime. Use this method to add services to the container.
  40. public void ConfigureServices(IServiceCollection services) {
  41. services.AddAntiforgery();
  42. services.AddAuthorization();
  43. // Add framework services.
  44. services.AddMvc();
  45. }
  46.  
  47. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  48. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  49. {
  50. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  51. loggerFactory.AddDebug();
  52.  
  53. if (env.IsDevelopment())
  54. {
  55. app.UseDeveloperExceptionPage();
  56. app.UseBrowserLink();
  57. }
  58. else
  59. {
  60. app.UseExceptionHandler("/Home/Error");
  61. }
  62.  
  63. app.UseStaticFiles();
  64.  
  65. app.UseCookieAuthentication();
  66.  
  67. app.UseMvc(config =>
  68. {
  69. config.MapRoute(
  70. name: "Default",
  71. template: "{controller}/{action}/{id?}",
  72. defaults: new { controller = "Home", action = "Index" }
  73. );
  74. });
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement