什么是ASP.NET中的会话,我该如何使用它?

时间:2022-04-06 14:18:37

Can someone explain the concept of sessions in ASP.NET? How do I use them, and how do cookies fit in?

有人可以解释ASP.NET中会话的概念吗?我如何使用它们,以及饼干如何适应?

4 个解决方案

#1


Session is a per-user object for persisting state between HTTP requests. It is good for storing information that you will need on the server to properly serve requests back to the user (e.g. user name, email, etc.).

Session是用于在HTTP请求之间保持状态的每用户对象。最好在服务器上存储您需要的信息,以便将请求正确地提供给用户(例如用户名,电子邮件等)。

ASP.NET places a cookie on the client's machine that contains a GUID (in the case of cookieless sessions, this GUID is placed on the URL). This GUID is the user's session ID. This identifier is retrieved on each HTTP request from the client by the ASP.NET runtime. Subsequently this identifier is used to rehydrate the user's session data from the session's data-store (either in memory or in the database).

ASP.NET在客户端的机器上放置一个包含GUID的cookie(在无cookie会话的情况下,此GUID放在URL上)。此GUID是用户的会话ID。 ASP.NET运行时从客户端的每个HTTP请求中检索此标识符。随后,此标识符用于从会话的数据存储(在内存或数据库中)中重新水合用户的会话数据。

#2


#3


Sounds like you're pretty new to ASP.NET. Rather than posting vague questions here, I would suggest you head over to http://www.ASP.net and check out their tutorials. They've got a lot of walkthroughs and articles that will give you a good overview of how ASP.NET state works.

听起来你是ASP.NET的新手。我建议你转到http://www.ASP.net并查看他们的教程,而不是在这里发布模糊的问题。他们有很多演练和文章,可以很好地概述ASP.NET状态的工作原理。

#4


A question like this makes me want to point you over to a post I did a while back (Should I Use a Framework While Learning Web Development) which will give you a heads up to other areas you might want to study up on. The topic of sessions is one of those bullet points.

这样的问题让我想指出你做了一段时间的帖子(我应该在学习Web开发的同时使用框架),这将让你了解你可能想要研究的其他领域。会议主题是其中一个要点。

I think that the idea of a session is well covered in the above posts so I won't further detail that!

我认为会话的想法在上面的帖子中有很好的涵盖,所以我不会进一步详细说明!

#1


Session is a per-user object for persisting state between HTTP requests. It is good for storing information that you will need on the server to properly serve requests back to the user (e.g. user name, email, etc.).

Session是用于在HTTP请求之间保持状态的每用户对象。最好在服务器上存储您需要的信息,以便将请求正确地提供给用户(例如用户名,电子邮件等)。

ASP.NET places a cookie on the client's machine that contains a GUID (in the case of cookieless sessions, this GUID is placed on the URL). This GUID is the user's session ID. This identifier is retrieved on each HTTP request from the client by the ASP.NET runtime. Subsequently this identifier is used to rehydrate the user's session data from the session's data-store (either in memory or in the database).

ASP.NET在客户端的机器上放置一个包含GUID的cookie(在无cookie会话的情况下,此GUID放在URL上)。此GUID是用户的会话ID。 ASP.NET运行时从客户端的每个HTTP请求中检索此标识符。随后,此标识符用于从会话的数据存储(在内存或数据库中)中重新水合用户的会话数据。

#2


#3


Sounds like you're pretty new to ASP.NET. Rather than posting vague questions here, I would suggest you head over to http://www.ASP.net and check out their tutorials. They've got a lot of walkthroughs and articles that will give you a good overview of how ASP.NET state works.

听起来你是ASP.NET的新手。我建议你转到http://www.ASP.net并查看他们的教程,而不是在这里发布模糊的问题。他们有很多演练和文章,可以很好地概述ASP.NET状态的工作原理。

#4


A question like this makes me want to point you over to a post I did a while back (Should I Use a Framework While Learning Web Development) which will give you a heads up to other areas you might want to study up on. The topic of sessions is one of those bullet points.

这样的问题让我想指出你做了一段时间的帖子(我应该在学习Web开发的同时使用框架),这将让你了解你可能想要研究的其他领域。会议主题是其中一个要点。

I think that the idea of a session is well covered in the above posts so I won't further detail that!

我认为会话的想法在上面的帖子中有很好的涵盖,所以我不会进一步详细说明!