Parameters VS Session Values

  • Thread starter Thread starter Sylvie
  • Start date Start date
S

Sylvie

When redirecting a page,

For example

CASE 1;

Response.Redirect("Page.aspx?Paramval=123");

in Page.aspx

string aaa = GetQueryString("Paramval")

CASE 2;

Session("Paramval") = 123
Response.Redirect("Page.aspx");

in Page.aspx

string aaa = Session("Paramval");

Which one is better?

Thanks
 
CASE 1;
Response.Redirect("Page.aspx?Paramval=123");

in Page.aspx

string aaa = GetQueryString("Paramval")

Pro: This does not require cookies and can be linked to from other sites
Con: The url can be changed by the user and you can't control it
CASE 2;

Session("Paramval") = 123
Response.Redirect("Page.aspx");

in Page.aspx

string aaa = Session("Paramval");

Pro: You control what is in the session, the user can't alter it
Con: The page can't be linked to from another site, requires cookies, and if
I sit idle at Page.aspx such that my session times out and I refresh then
the Session variable has gone. Also this requires server-side storage for
each active user.

So neither is "better", it depends what you want.
 
Is there a relation between Session Variables and cookies ?

My purpose is to pass a datarow id to page.aspx and place this is in a
hidded field, so it wont be erased

But what is the relation between cookies and session values?

is there an alternative way of using session vals? Everyone uses them and if
cookiless system ?
 
When you first use a site a Session is created and the Session ID is stored
in a cookie. With each subsequent page request that cookie is given to the
site and your request is linked with your active Session. The actual
session values are all stored on the server, but the Session ID is stored in
a cookie. If you disable cookies then sessions won'r work and every page
will be like accessing the site for the first time.

Note that there is now a way to configure your site using cookieless
sessions where the session ID is automatically apended to each URL instead.

If you want to store values on the page that are passed back when the page
is submitted you could look at using the ViewState instead.
 
Back
Top