我遇到会话问题在关闭浏览器后,我的会话将过期,并且在重新打开浏览器后,我必须再次登录。我不想使我的会话在浏览器关闭时过期。我在我的web.config文件中使用它:
<authentication>
<forms loginUrl="~/account/login" name="astroswamig" slidingExpiration="true" timeout="1000"></forms>
</authentication>
<sessionState mode="StateServer" cookieless="false" timeout="1000" />
这在我的控制器中:
string str = JsonConvert.SerializeObject(user);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.CustEmail, DateTime.Now, DateTime.Now.AddDays(120), true, str);
string enctryptTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authCustCookie = new HttpCookie(FormsAuthentication.FormsCookieName, enctryptTicket);
authCustCookie.Domain = "xyz.com";
Response.Cookies.Add(authCustCookie);
问题中的web.config
示例正在使用StateServer
模式,因此进程外ASP.NET状态服务正在存储状态信息。您将需要配置状态服务。请在此处的“ STATESERVER MODE(OUTPROC MODE)”部分中查看如何执行此操作的示例:
https://www.c-sharpcorner.com/UploadFile/484ad3/session-state-in-Asp-Net/
另外,请务必阅读以上链接文章的“缺点”部分,以确保该方法可以满足您的需求。
管理用户会话的另一种方法是使用InProc
通过工作进程管理会话的模式。然后,您可以获取和设置HttpSessionState
属性,如下所示:
https://www.c-sharpcorner.com/UploadFile/3d39b4/inproc-session-state-mode-in-Asp-Net/
还有这里:
再次确保InProc
在上面链接的文章中注意模式的优缺点,以确定哪种方法最适合您的需求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句