Startup.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Authentication.Cookies;
  6. using Microsoft.AspNetCore.Builder;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.AspNetCore.HttpsPolicy;
  9. using Microsoft.EntityFrameworkCore;
  10. using Microsoft.Extensions.Configuration;
  11. using Microsoft.Extensions.DependencyInjection;
  12. using Microsoft.Extensions.Hosting;
  13. using SuperCms.Database;
  14. using SuperCms.Repositories;
  15. namespace SuperCms
  16. {
  17. public class Startup
  18. {
  19. public Startup(IConfiguration configuration)
  20. {
  21. Configuration = configuration;
  22. }
  23. public IConfiguration Configuration { get; }
  24. // This method gets called by the runtime. Use this method to add services to the container.
  25. public void ConfigureServices(IServiceCollection services)
  26. {
  27. //services.AddControllersWithViews();
  28. services.AddTransient<ISuperCmsRepo, SuperCmsRepo>();
  29. services.AddSingleton<IConfiguration>(Configuration);
  30. services.AddDbContext<ModelContext>(options => options
  31. .UseOracle(Configuration.GetSection("ConnectionMytel").Value,
  32. providerOptions => providerOptions.CommandTimeout(60).UseRelationalNulls(true).MinBatchSize(2)));
  33. services.AddMvc();
  34. //.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
  35. //.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
  36. services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
  37. services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
  38. services.AddSession(options =>
  39. {
  40. options.IdleTimeout = TimeSpan.FromSeconds(600);
  41. options.Cookie.HttpOnly = true;
  42. options.Cookie.IsEssential = true;
  43. });
  44. //services.AddSession();
  45. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
  46. services.AddHttpContextAccessor();
  47. }
  48. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  49. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  50. {
  51. if (env.IsDevelopment())
  52. {
  53. app.UseDeveloperExceptionPage();
  54. }
  55. else
  56. {
  57. app.UseExceptionHandler("/Home/Error");
  58. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  59. app.UseHsts();
  60. }
  61. app.UseSession();
  62. app.UseCookiePolicy();
  63. app.UseHttpsRedirection();
  64. app.UseStaticFiles();
  65. app.UseRouting();
  66. app.UseAuthorization();
  67. app.UseEndpoints(endpoints =>
  68. {
  69. endpoints.MapControllerRoute(
  70. name: "default",
  71. pattern: "{controller=Home}/{action=Index}/{id?}");
  72. });
  73. }
  74. }
  75. }