locked
web session RRS feed

  • Question

  • User-1085721443 posted

    Please who can explain what a web session means? On the internet all i can see is user session, i want to know if it means the same thing? If not, an explanation and how they can be implemented. Thank you!!!

    Monday, December 17, 2012 6:40 PM

Answers

  • User-40287846 posted

    Web is stateless, which means a new instance of a web page class is re-created each time the page is posted to the server.  As we all know, HTTP is a stateless protocol, it can't hold client information on a page. If the user inserts some information and move to the next page,  that data will be lost and the user would not be able to retrieve that information.Session provides a facility to store information  on server memory.

     

    Example . I Log in a site i want to keep username for all pages or some particular pages.

    page1.aspx

    Session["user"] = "test";

    this one is redirecting to page2.aspx  and page2.aspx is redirecting to page3.aspx

    i want to access user name in page3.aspx

    like

    string username;

    username = Session["uesr"].ToString();

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 17, 2012 6:46 PM
  • User-861818263 posted
    • Viewstate
    • Session Variables
    • Application Variables
    • Cache
    • Cookies

    Now the question arises that when to use what?

    1- Viewstate

    Viewstate is a hidden fields in an ASP.NET page, contains state of those controls on a page whose “EnableViewstate” property is “true”.

    You can also explicitly add values in it, on an ASP.NET page like:

    Viewstate.Add( “TotalStudents”, “87″ );

    Viewstate should be used when you want to save a value between different roundtrips of a single page as viewstate of a page is not accessible by another page.

    Because Viewstate renders with the page, it consumes bandwidth, so be careful to use it in applications to be run on low bandwidth.

    2- Session Variable

    Session variables are usually the most commonly used.

    When a user visits a site, it’s sessions starts and when the user become idle or leave the site, the session ends.

    Session variables should be used to save and retrieve user specific information required on multiple pages.

    Session variables consumes server memory, so if your may have a huge amount visitors, use session very carefully and instead of put large values in it try to put IDs and references.

    Sessions are not cookies, but they can work together to create the illusion of persistence. Persistence is the process of ensuring that the user is connected to the same server ervery time they make a request within the boundaries of a single session. It is most often implemented using a cookie containing the server session Id, because by this method we can determine where a user's session is currently stored.

    for more information  :- http://support.microsoft.com/kb/307598 


    3- Application variables

    Application variables are shared variables among all users of a web application

    Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications

    Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.


    4- Cache

    Cache is probably the least used state feature of ASP.NET.

    Cache is basically a resource specific state persistence feature, means unlike session it stick with resource instead of user, for instance: pages, controls etc.

    Cache should be used or frequently used pages, controls, and data structures

    Data cache can be used to cache frequently used list of values e.g. list of products

    5- Cookies

    Cookies are some values saved in browsers by the website to retrivbbe and use afterwards.

    Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved preferences.

    Cookies are also used to facilitate auto login by persisting user id in a cookie save in user’s browser.

    Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser.


    Finally remember the following points on your finger-tips:

    • Viewstate is bandwidth hungry
    • Session variables are memory hungry as per number of users
    • Applications variables are shared
    • Cache is memory hungry as per number of resources
    • Cookies are the least secure
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2012 12:51 AM
  • User-166373564 posted

    Hi ifi

    Moreover, Session Mode: InProc session mode, StateServer session mode, SQL Server Session Mode, Custom Session Mode.

    You could learn more information about session mode here(http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net#11)

    Kind regards

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2012 11:16 PM

All replies

  • User-40287846 posted

    Web is stateless, which means a new instance of a web page class is re-created each time the page is posted to the server.  As we all know, HTTP is a stateless protocol, it can't hold client information on a page. If the user inserts some information and move to the next page,  that data will be lost and the user would not be able to retrieve that information.Session provides a facility to store information  on server memory.

     

    Example . I Log in a site i want to keep username for all pages or some particular pages.

    page1.aspx

    Session["user"] = "test";

    this one is redirecting to page2.aspx  and page2.aspx is redirecting to page3.aspx

    i want to access user name in page3.aspx

    like

    string username;

    username = Session["uesr"].ToString();

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 17, 2012 6:46 PM
  • User-861818263 posted
    • Viewstate
    • Session Variables
    • Application Variables
    • Cache
    • Cookies

    Now the question arises that when to use what?

    1- Viewstate

    Viewstate is a hidden fields in an ASP.NET page, contains state of those controls on a page whose “EnableViewstate” property is “true”.

    You can also explicitly add values in it, on an ASP.NET page like:

    Viewstate.Add( “TotalStudents”, “87″ );

    Viewstate should be used when you want to save a value between different roundtrips of a single page as viewstate of a page is not accessible by another page.

    Because Viewstate renders with the page, it consumes bandwidth, so be careful to use it in applications to be run on low bandwidth.

    2- Session Variable

    Session variables are usually the most commonly used.

    When a user visits a site, it’s sessions starts and when the user become idle or leave the site, the session ends.

    Session variables should be used to save and retrieve user specific information required on multiple pages.

    Session variables consumes server memory, so if your may have a huge amount visitors, use session very carefully and instead of put large values in it try to put IDs and references.

    Sessions are not cookies, but they can work together to create the illusion of persistence. Persistence is the process of ensuring that the user is connected to the same server ervery time they make a request within the boundaries of a single session. It is most often implemented using a cookie containing the server session Id, because by this method we can determine where a user's session is currently stored.

    for more information  :- http://support.microsoft.com/kb/307598 


    3- Application variables

    Application variables are shared variables among all users of a web application

    Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications

    Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.


    4- Cache

    Cache is probably the least used state feature of ASP.NET.

    Cache is basically a resource specific state persistence feature, means unlike session it stick with resource instead of user, for instance: pages, controls etc.

    Cache should be used or frequently used pages, controls, and data structures

    Data cache can be used to cache frequently used list of values e.g. list of products

    5- Cookies

    Cookies are some values saved in browsers by the website to retrivbbe and use afterwards.

    Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved preferences.

    Cookies are also used to facilitate auto login by persisting user id in a cookie save in user’s browser.

    Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser.


    Finally remember the following points on your finger-tips:

    • Viewstate is bandwidth hungry
    • Session variables are memory hungry as per number of users
    • Applications variables are shared
    • Cache is memory hungry as per number of resources
    • Cookies are the least secure
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2012 12:51 AM
  • User-166373564 posted

    Hi ifi

    Moreover, Session Mode: InProc session mode, StateServer session mode, SQL Server Session Mode, Custom Session Mode.

    You could learn more information about session mode here(http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net#11)

    Kind regards

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 18, 2012 11:16 PM