// 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; }); #region 连接字符串 //连接SQL server //var sqlConnection = @"Data Source=120.78.198.92;Initial Catalog=WZZ;Persist Security Info=True;User ID=sa;Password=Woshimayu1998;"; //services.AddDbContext<MyDbContext>(option => option.UseSqlServer(sqlConnection)); services.AddDbContext <MyDbContext>(d => d.UseMySQL(Configuration.GetConnectionString("MysqlConnection"))); #endregion BLLDIRegister sdr = new BLLDIRegister(); sdr.DIRegister_DAL(services); ////使用session //services.AddDistributedSqlServerCache(o => //{ // o.ConnectionString = sqlConnection; // o.SchemaName = "dbo"; // o.TableName = "SessionState"; //}); services.AddSession(o => { o.IdleTimeout = TimeSpan.FromMinutes(30); o.Cookie.HttpOnly = true; o.Cookie.IsEssential = true; }); //给登陆注解设置路径 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(o => { o.LoginPath = "/Admin_Login/Index"; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// 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; }); #region 连接字符串 //连接字符串 //var sqlConnection = Configuration.GetConnectionString("SqlServer"); //services.AddDbContext<MyDbcontext>(option => option.UseSqlServer(sqlConnection)); //var sqlConnection = @"Data Source=120.78.198.92;Initial Catalog=WZZ;Persist Security Info=True;User ID=sa;Password=Woshimayu1998;"; //services.AddDbContext<MyDbContext>(option => option.UseSqlServer(sqlConnection)); services.AddDbContext <MyDbContext>(d => d.UseMySQL(Configuration.GetConnectionString("MysqlConnection"))); #endregion BLLDIRegister sdr = new BLLDIRegister(); sdr.DIRegister_DAL(services); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }