ASP Session ID

Posted on 2011-05-10
Last Modified: 2012-08-13
I am using a cookieless session id.  My issue is that every page in my application is assigning a new session id when a page is new page is loaded.

I can't seem to figure out how to use the same active session for every page in the instance.

Question by:gdspeare
    LVL 13

    Expert Comment

    How are you opening new pages - 1) through links or by typing the urls, 2)in same tab, in new tab or in new window?

    If you open different pages in same tab, then everything should work fine. But in different tabs, you may face problem.

    Author Comment

    new pages are opened from the menu in the same tab.

    and new session ids are being given.
    LVL 13

    Expert Comment

    Then I think that you are using absolute URLs or relative to application root.

    I tried it this way: Created two pages Page1.aspx and Page2.aspx in same folder. On Page1.aspx, i added two links to page Page2.aspx as:

    <a href="Page2.aspx">Link 1</a>    
    <a href="/Page2.aspx">Link 2</a>

    If I click on Link 1, it uses the same session id. But if I click Link 2, it assigns a new session id.

    I am not sure but it seems that this behavior is by design and probably we cannot change it.
    Although its not exactly the solution to your problem, but it will help you understand a bit about cookiless sessions.
    LVL 13

    Expert Comment

    Just found on an article that we can use absolute urls like this:

    <a runat="server"
        href=<% =Response.ApplyAppPathModifier("/Page2.aspx")%> >Link 2</a>

    Here is the link to that post:
    LVL 13

    Accepted Solution

    In above comment, remove runat="server".

    Try following code:

    <a href="Page2.aspx">Link 1</a>    
    <a href="/Page2.aspx">Link 2</a>  (Only this gives a new session id)
    <a runat="server" href="~\Page2.aspx">Link 3</a>
    <a href='<%=Request.ApplyAppPathModifier("/Page2.aspx") %>'>Link 4</a>

    Also, see the client side code generated by above code by using View Source option in the browser.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now