基于.NET Core 3.1 网站开发和部署的方法
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDistributedMemoryCache(); services.AddSession(options => { // Set a short timeout for easy testing. options.IdleTimeout = TimeSpan.FromSeconds(300); options.Cookie.HttpOnly = true; // Make the session cookie essential options.Cookie.IsEssential = true; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options=>{ options.Cookie.HttpOnly=true; options.ExpireTimeSpan=TimeSpan.FromMinutes(5); options.LoginPath="/admin"; // options.AccessDeniedPath="/403.html"; } ); string connString = Configuration.GetConnectionString("HotelWeb"); services.AddDbContext<DAL.HotelWebDbContext>(options => options.UseMySql(connString, x => x.ServerVersion("5.5.64-mariadb"))); } 启用认证服务添加的位置有要求:必须在app.UseRouting 和 app.UseEndpoints 之间。 (编辑:92站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |