Can you maintain session state when using Server.Transfer() ?

Discussion in 'ASP .Net' started by David Berman, Feb 3, 2005.

  1. David Berman

    David Berman Guest

    It seems that my site is losing session information when using
    Server.Transfer. I have a page called PictureGallery.aspx. It takes an
    argument which is an index id, so it would look like
    PictureGallery.aspx?id=30 to display gallery 30. In this way I have a
    database driven picture gallery. To improve indexing, I put code in
    Global.asax to allow me to get to the same page with a url like this:
    Pictures_30.aspx. There is no Pictures_30.aspx, the
    Application_BeginRequest parses the url, captures it, and calls
    Server.Transfer("PictureGallery.aspx?id=30");

    However, when I try to access a session variable on the page, I get the
    error:
    HttpException (0x80004005): Session state can only be used when
    enableSessionState is set to true, either in a configuration file or in
    the Page directive]

    If I go to the page directly, instead of using the Server.Transfer, the
    page works fine. Why is this happening? Is there a workaround?

    I am using this redirect system to make it as easy as possible to be
    indexed by search engines or for people to type in a url to email a
    friend to view a picture gallery.

    Thank you very much.

    David



    Meet people for friendship, contacts,
    or romance using free instant messaging software! See a picture you
    like? Click once for a private conversation with that person!

    http://www.SocialNetwork.com

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    David Berman, Feb 3, 2005
    #1
    1. Advertising

  2. Here's a nice, simple way to pass values from one page to another:
    (VB.NET code)

    'Add data to the context object before transferring
    Context.Items("myParameter") = x
    Server.Transfer("WebForm2.aspx")

    Then, in WebForm2.aspx:

    'Grab data from the context property
    Dim x as Integer = CType(Context.Items("myParameter"),Integer)

    Of course there are a number of ways to pass values from one page to
    another, such as using the querystring, cookies, session,
    context, saving to a temporary table in the database between each page, etc.
    You'll have to decide which technique is best for your application.
    Here are several good articles on the subject to help you decide.
    http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

    http://www.aspalliance.com/kenc/passval.aspx

    http://www.dotnetbips.com/displayarticle.aspx?id=79

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "David Berman" <> wrote in message
    news:...
    > It seems that my site is losing session information when using
    > Server.Transfer. I have a page called PictureGallery.aspx. It takes an
    > argument which is an index id, so it would look like
    > PictureGallery.aspx?id=30 to display gallery 30. In this way I have a
    > database driven picture gallery. To improve indexing, I put code in
    > Global.asax to allow me to get to the same page with a url like this:
    > Pictures_30.aspx. There is no Pictures_30.aspx, the
    > Application_BeginRequest parses the url, captures it, and calls
    > Server.Transfer("PictureGallery.aspx?id=30");
    >
    > However, when I try to access a session variable on the page, I get the
    > error:
    > HttpException (0x80004005): Session state can only be used when
    > enableSessionState is set to true, either in a configuration file or in
    > the Page directive]
    >
    > If I go to the page directly, instead of using the Server.Transfer, the
    > page works fine. Why is this happening? Is there a workaround?
    >
    > I am using this redirect system to make it as easy as possible to be
    > indexed by search engines or for people to type in a url to email a
    > friend to view a picture gallery.
    >
    > Thank you very much.
    >
    > David
    >
    >
    >
    > Meet people for friendship, contacts,
    > or romance using free instant messaging software! See a picture you
    > like? Click once for a private conversation with that person!
    >
    > http://www.SocialNetwork.com
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Steve C. Orr [MVP, MCSD], Feb 3, 2005
    #2
    1. Advertising

  3. David Berman

    David Berman Guest

    Thanks for your reply. I can see how you can use this mechanism to pass
    arguments from one page to another. However, the state information is
    missing when I do a transfer. Suppose i use this method to put the
    state object into a container as you illustrated, and pass it, can I
    then modify the code of the page to assign the context.session variable
    to point to the object in the container I passed?

    Basically, I know that the page works fine when I execute it as
    Page.aspx?argument=xxx but it doesn't work when I do a server transfer
    to it, because it says I don't have session state information in that
    context.



    Meet people for friendship, contacts,
    or romance using free instant messaging software! See a picture you
    like? Click once for a private conversation with that person!

    www.SEN.us

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    David Berman, Feb 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Bezzina
    Replies:
    0
    Views:
    510
    Adrian Bezzina
    Aug 7, 2003
  2. shamanthakamani
    Replies:
    1
    Views:
    3,475
    Natty Gur
    Nov 20, 2003
  3. Not Liking Dot Net Today
    Replies:
    0
    Views:
    595
    Not Liking Dot Net Today
    Apr 21, 2004
  4. JLSSCH
    Replies:
    0
    Views:
    552
    JLSSCH
    Apr 18, 2005
  5. zwieback89
    Replies:
    1
    Views:
    311
    Roland Hall
    Feb 2, 2007
Loading...

Share This Page