登录后如何存储用户ID [英] How store user id after login

查看:281
本文介绍了登录后如何存储用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在创建网站。

问题是我在几分钟之后登录用户ID到期。

请解决这个问题问题。


I am creating website.
problem is when i login after few minutes user id is expire.
Please solve this problem.

推荐答案

你可以将它存储在会话Session [id] = id;
you can store it in session Session["id"] = id;


1中。在ASP.NET应用程序中,当前用户的会话可能会在几分钟或更长时间后过期,具体取决于 web.config 中的相关设置。



为了解决这个问题,您应该使用 web.config 中的下一个设置:

1. In a ASP.NET application the session for the current user could expire after few or more minutes, based on the associated setting from web.config.

In order to fix this you should use the next setting from your web.config:
<sessionstate mode="InProc" cookieless="false" timeout="1440" />





2.如果你想保留回发之间的用户ID,在用户登录后,你应该将其值缓存在当前 Session 中,如下一个ex ample:



2. If you want to preserve the user ID between postbacks, after the user login you should cache its value in the current Session like in the next example:

Session["UserID"]= userID;



然后在postabcks期间,当您需要用户ID时,您可以从会话缓存中访问它,如下面的代码所示:


Then during the postabcks, when you need the user ID, you could access it form the Session cache like in the code below:

int userID = (int)Session["UserID"];


请参阅链接..

所有关于会议..

http://msdn.microsoft.com/en-us/library/ms178581(v = vs.100).aspx [ ^ ]

http://asp.net-tutorials.com/state/sessions/ [ ^ ]

http ://runnable.com/Uhxav7qocnlxAAA8/asp-net-how-to-use-session [ ^ ]
See links..
All about the Session..
http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx[^]
http://asp.net-tutorials.com/state/sessions/[^]
http://runnable.com/Uhxav7qocnlxAAA8/asp-net-how-to-use-session[^]


这篇关于登录后如何存储用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆