locked
Asp Session ID different with Sys.Net.WebRequest RRS feed

  • Question

  • User-2133509214 posted

    I don't understand why the Asp Net Session ID is different between the main page and the page call by Sys.Net.WebRequest object.

    I have in my cookie the variable Asp.Net_SessionId right on the client script, but on the server with the call by Sys.Net.WebRequest object, i have a anothe value of session id and then i don't have the same session that the main page.
    I don't have any HttpModule to catch Session or other.

    Thanks.
    Eric.

     

    Friday, June 22, 2007 9:11 AM

Answers

  • User-900677162 posted

    HI, Eric:

    The HttpWebRequest class has a CookieContainer property that is null by default. Create a new CookieContainer and assign it to the request. When you get the response you can call CookieContainer.GetCookies( requestUri ) and look through the cookies. The ASP session cookis is called "ASP _SessionId", the next time a request is made create a cookie container for it and add the session cookie and then ASP will recognize the session

    the session (on the serverside) is associated
    with client via a cookie variable named "ASP.NET_SessionId". If we want to
    mantain the session outside , not via asp.net page request, we need to
    manually retrieve the cookie variable from cookie collection and repost it
    next time so as to maintain the association. In addition, as the other
    customer has mentioned, if
    the client doesn't support cookie, the ASP.NET serverside also provide a
    cookie less session implmentation , which will put the session id as
    encryped value in the url, thus, we can't use cookie variable to retrieve
    the sessoinid. For detailed info on the ASP.NET session implemention, you
    can view the following reference in MSDN:

    #Underpinnings of the Session State Implementation in ASP.NET
    http://msdn.microsoft.com/library/en...ionstate.asp?f
    rame=true

    Also, here is a tech ariticle discussing the cookie in ASP.NET
    #basics of cookies in asp.net
    http://msdn.microsoft.com/library/de...us/dv_vstechar
    t/html/vbtchaspnetcookies101.asp

    Hope they're also helpful to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 24, 2007 11:06 PM