Usage of Session object in ASP.NET

后端 未结 5 1470
时光说笑
时光说笑 2021-01-19 04:20

I\'ve just been given a new task to bootstrap a website created by someone else. But I\'m absolutely new to Web. The website is in ASP.NET,C#. The code itself is not hard to

5条回答
  •  遥遥无期
    2021-01-19 05:09

    HTTP by nature is stateless. The WebServer doesn't know any details after it processes the request and sends back to the client. Thus, any subsequent requests are like fresh requests to the server.

    To Enable the Server to remember & subsequently recognize what it served to the client, ASP.NET uses various mechanisms of which Session is one of them.

    Session is created per user. So, in your Page, you are fetching the "connSTR" are storing it. Whenever a subsequent request comes from the same user, by querying Session with the key

    Session["connSTR"]
    

    you get back its value. Since Session is an Object, its casted as a string in your code.

提交回复
热议问题