Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Can you maintain session state when using Server.Transfer() ? (http://www.velocityreviews.com/forums/t95914-can-you-maintain-session-state-when-using-server-transfer.html)

David Berman 02-03-2005 03:12 AM

Can you maintain session state when using Server.Transfer() ?
 
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] 02-03-2005 05:50 AM

Re: Can you maintain session state when using Server.Transfer() ?
 
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/is...e/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" <david_berman@bose.com> wrote in message
news:Oh62A5ZCFHA.2380@tk2msftngp13.phx.gbl...
> 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 02-03-2005 05:07 PM

Re: Can you maintain session state when using Server.Transfer() ?
 
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!


All times are GMT. The time now is 01:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.