Startup.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using CZFW.Core;
  6. using CZFW.Framework;
  7. using CZFW.Framework.Model;
  8. using CZFW.MDB;
  9. using CZFW.MDB.Util;
  10. using Microsoft.AspNetCore.Builder;
  11. using Microsoft.AspNetCore.Hosting;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.AspNetCore.HttpOverrides;
  14. using Microsoft.AspNetCore.Mvc;
  15. using Microsoft.EntityFrameworkCore;
  16. using Microsoft.Extensions.Configuration;
  17. using Microsoft.Extensions.DependencyInjection;
  18. using Microsoft.Extensions.Logging;
  19. namespace CZFW.CMS.Builder
  20. {
  21. public class Startup
  22. {
  23. public Startup(IConfiguration configuration)
  24. {
  25. Configuration = configuration;
  26. ConfigHelper.Configs = configuration;
  27. }
  28. public IConfiguration Configuration { get; }
  29. // This method gets called by the runtime. Use this method to add services to the container.
  30. public void ConfigureServices(IServiceCollection services)
  31. {
  32. //services.AddDbContext<CZDbContext>(options =>
  33. //{
  34. // options.UseMySql("Data Source=sp5045a8d445fe0.mysql.rds.aliyuncs.com;user id=sp5045a8d445fe0;password=CZKJggkl3102;Initial Catalog=czfw_db;SslMode=none;",
  35. // mysqlOptions =>
  36. // {
  37. // mysqlOptions.ServerVersion("5.1");
  38. // }
  39. // );
  40. //});
  41. services.ConfigureFrameworkServices();
  42. services.ConfigureMDBServices();
  43. services.AddMemoryCache();
  44. services.AddSession(options =>
  45. {
  46. options.Cookie.Name = "_sid__";
  47. options.IdleTimeout = TimeSpan.FromMinutes(60);
  48. });
  49. services.AddCors(Options =>
  50. {
  51. Options.AddPolicy("any", builder =>
  52. {
  53. builder.AllowAnyHeader()
  54. .AllowAnyMethod()
  55. .AllowAnyOrigin()
  56. .AllowCredentials();
  57. });
  58. });
  59. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  60. CZHttpContext.ServiceProvider = services.BuildServiceProvider();
  61. }
  62. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  63. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  64. {
  65. // loggerFactory.AddLog4Net();
  66. if (env.IsDevelopment())
  67. {
  68. app.UseDeveloperExceptionPage();
  69. }
  70. else
  71. {
  72. app.UseExceptionHandler("/Home/Error");
  73. }
  74. app.UseStaticFiles();
  75. app.UseCookiePolicy();
  76. app.UseForwardedHeaders(new ForwardedHeadersOptions
  77. {
  78. ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
  79. });
  80. app.UseSession();
  81. app.UseMvc(routes =>
  82. {
  83. routes.MapRoute(
  84. name: "resource", template: $"{Constants.RESOURCE_FILE_URL_PREFIX}/{{siteId}}/{{fileType}}/{{fileName}}",
  85. defaults: new { controller = "Resource", action = "Load" });
  86. routes.MapRoute(
  87. name: "content", template: $"{Constants.CONTENT_FILE_URL_PREFIX}/{{tplId}}/{{theme}}/{{folder}}/{{typeFolder}}/{{fileName}}",
  88. defaults: new { controller = "Resource", action = "Content" });
  89. routes.MapRoute(
  90. name: "default",
  91. template: "{controller=Home}/{action=Index}/{id?}");
  92. });
  93. }
  94. }
  95. }