none
ASP.NET and Sessions RRS feed

  • Question

  • I have successfully created many working websites using PHP and Notepad.
    I have just started to use ASP.NET using WebMatrix3. I have created a fully working website as far as navigation is concerned on my development machine. The problem I have is dealing with sessions when I go live - which I have not yet tried because I don't understand what is going on.

    With PHP it was easy.
    <?php SESSION_START(); ?>
    <html>
       ... html script ...
    </html>
    You just began every script with SESSION_START(); and the PHP compiler on the server took care of everything.
    It wasn't necessary to check anything else at all.

    It doesn't seem to be that simple with ASP.NET.
    I know that when a surfer makes their first request from the browser - say by surfing to the home page - then the IIS compiler on the server creates a SessionId. This Id is stored on the client's machine in a cookie.
    But if cookies are disabled then this won't work! So how do I cover that eventuality?
    Apparently I can use the Web.config file to set things up - but I can't see where the script in this file gets executed. Is it automatically executed in the background on the first request from the browser? Or what?

    Then I read a tutorial that said the IIS compiler on the server creates a new SessionId for every request from a browser - unless the client has created content; but what does that mean? What is this 'content'? If the surfer simply browses from page to page is that 'creating content'?

    So - do I have to begin every script with a check that a SessionId exists? Or can I assume that the IIS compiler takes care of everything just like a PHP compiler? Or do I have to begin each script with a statement like SESSION_START()?

    "Experts often fail to realise that non-experts don't understand things that are perfectly clear to themselves".
    It might be clear as crystal to you but it's cloudy as mud to me!
    Any help would be greatly appreciated.
    Please don't take anything for granted.

    Thanks

     

     

     


    ME

    Wednesday, April 16, 2014 7:35 PM

Answers

  • Hi,

    Here is the wrong forum about the issue. I suggest that you can post it to asp.net forum where you can get better answers.

    http://forums.asp.net/

    In addition, By default there are 3 places where the actual session data can be stored:

    • In-Proc: the session is stored into the memory of the application (fastest but if you have multiple servers in a server farm this won't work)
    • Out-of-Proc: the data is stored into a separate server which has the State service installed (the data is stored in the memory of a separate machine meaning that multiple web servers can work in a web farm)
    • SqlServer: the data is stored in SQL Server (it's the slowest but most reliable as the session data is stored in a SQL Server database and could servive if the Session server crashes which is not the case with Out-Of-Proc)
    • Custom implementation: thanks to the extensibility of ASP.NET you could write your own session provider and store the data wherever you like.

    For more information, you can refer here

    http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net

    #ASP.NET Session State Overview

    http://msdn.microsoft.com/en-us/library/ms178581.aspx

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pengzhen Song Tuesday, April 29, 2014 1:34 AM
    Thursday, April 17, 2014 8:54 AM

All replies

  • Hi,

    Here is the wrong forum about the issue. I suggest that you can post it to asp.net forum where you can get better answers.

    http://forums.asp.net/

    In addition, By default there are 3 places where the actual session data can be stored:

    • In-Proc: the session is stored into the memory of the application (fastest but if you have multiple servers in a server farm this won't work)
    • Out-of-Proc: the data is stored into a separate server which has the State service installed (the data is stored in the memory of a separate machine meaning that multiple web servers can work in a web farm)
    • SqlServer: the data is stored in SQL Server (it's the slowest but most reliable as the session data is stored in a SQL Server database and could servive if the Session server crashes which is not the case with Out-Of-Proc)
    • Custom implementation: thanks to the extensibility of ASP.NET you could write your own session provider and store the data wherever you like.

    For more information, you can refer here

    http://www.codeproject.com/Articles/32545/Exploring-Session-in-ASP-Net

    #ASP.NET Session State Overview

    http://msdn.microsoft.com/en-us/library/ms178581.aspx

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Pengzhen Song Tuesday, April 29, 2014 1:34 AM
    Thursday, April 17, 2014 8:54 AM
  • If cookies are disabled, well, you can't do anything since the best way to handle sessions is via Cookies.

    You can show a notice to warn the user to enable cookies.

    Thursday, April 17, 2014 7:48 PM