views:

613

answers:

4

I would like to be able to use the same Session variable when transferring to another app.

Does Response.Redirect use the same session or start a new one?

I am using c#, aspnet 3.5

+6  A: 

Response.Redirect does nothing with the session. The session is tied (typically) to a cookie associated with the URI of the web app. If you switch to another web app on another server or a separate URI, the session will not carry over even if you managed to preserve the cookie.

Can you clarify what problem it is you're trying to solve?

spoulson
I'm trying to access a value set in app1 in app2 without passing it visibly in the url as a parameter.
Lill Lansey
I don't think that is going to work. You could POST it over, though.
AndyMcKenna
@Lill Lansey-If that's that case, you might want to reword your question.
John MacIntyre
+1  A: 

It uses the same session.

EDIT: That is assuming the new URL would have used the same session anyway.

AndyMcKenna
+3  A: 

Response.Redirect sends an Http Response to the browser with a status code of 302 Found and a header Location: {redirection-url}.

The browser receives this response, and knows to send a new request to the {redirection-url} when it receives a response with a status code of 302 Found.

That's all that happens.

Response.Redirect does not start or stop or have anything to do with any sessions.

Justice
A: 

If you are trying to access session variables from a different app then thats not going to work as far as I remember. Session variables are only valid within the one app.

If you are trying to just redirect to another folder within the same app then the session variables are available.

If the two apps are indeed separate you could look at storing the session objects in a database and passing the sessionID to the new app using either a POST or a url parameter, however, neither of these are very secure and leave the app open to hacking without proper care being taken to ensure the users identity.

Mauro
The long term plan is to pass the info between apps securely using a handshake involving both storing info in a database and passing a url parameter, but I was just looking for a way to test some code quickly now.
Lill Lansey