Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Thursday, March 29, 2012

session value

I am using belove code.I want to send session's value a variable in another
page.

How can I take session value.

script="<Language=VBScript> session(\"Id\")= ";

script+= kullaniciId;

script+="</script>";

Page.RegisterStartupScript("Startup", script);

Thanks.Hello Selen,
The result of your code will result code like that in the HTML page sent
to the browser
<script language=VBScript>
session("id")=123
</script>
and this code is a client side code so you can't affect the session
object on the server !!! I think you have to change you technique. If I
misunderstand you please tell me.

Thanks

--
Mohamed Sharaf
Microsoft GTSC Developer support for Middle East

"selen" <skiyanc@.yahoo.com> wrote in message
news:OR$qP9M4DHA.488@.TK2MSFTNGP12.phx.gbl...
> I am using belove code.I want to send session's value a variable in
another
> page.
> How can I take session value.
>
>
> script="<Language=VBScript> session(\"Id\")= ";
> script+= kullaniciId;
> script+="</script>";
> Page.RegisterStartupScript("Startup", script);
>
> Thanks.
Thank you.I find solution.
I used Session["key"]="value";
string=(string)Session["key"];
"Mohamed Sharaf" <Mohamed.Sharaf@.egdsc.microsoft.com>, iletide unu yazd
news:%23CALSVN4DHA.2388@.TK2MSFTNGP09.phx.gbl...
> Hello Selen,
> The result of your code will result code like that in the HTML page
sent
> to the browser
> <script language=VBScript>
> session("id")=123
> </script>
> and this code is a client side code so you can't affect the session
> object on the server !!! I think you have to change you technique. If I
> misunderstand you please tell me.
> Thanks
> --
> Mohamed Sharaf
> Microsoft GTSC Developer support for Middle East
>
> "selen" <skiyanc@.yahoo.com> wrote in message
> news:OR$qP9M4DHA.488@.TK2MSFTNGP12.phx.gbl...
> > I am using belove code.I want to send session's value a variable in
> another
> > page.
> > How can I take session value.
> > script="<Language=VBScript> session(\"Id\")= ";
> > script+= kullaniciId;
> > script+="</script>";
> > Page.RegisterStartupScript("Startup", script);
> > Thanks.

Session var lost using InProc or StateServer mode

On my development machine my application works fine but on the
deployment server my session variable gets lost after a postback on a
webform. By doing a watch on the Session object I can see that the
SessionId is changing and the mode is StateServer. (I changed from
InProc to StateServer to try to fix the problem but it didn't have any
effect.
Details:
- Win 2k Server/IIS 5.0/.NET Framework 1.1
- I have disabled virus protection.
- The StateServer service is running.
Any ideas are greatly appreciated.
MichaelIs there an underscore character ("_") in the name of your deployment
server? There's a known bug in that case.
--
John Saunders
johnwsaundersiii at hotmail
"MG" <kloodge@.yahoo.com> wrote in message
news:8be4d6f4.0407081008.ed2152f@.posting.google.com...
> On my development machine my application works fine but on the
> deployment server my session variable gets lost after a postback on a
> webform. By doing a watch on the Session object I can see that the
> SessionId is changing and the mode is StateServer. (I changed from
> InProc to StateServer to try to fix the problem but it didn't have any
> effect.
> Details:
> - Win 2k Server/IIS 5.0/.NET Framework 1.1
> - I have disabled virus protection.
> - The StateServer service is running.
> Any ideas are greatly appreciated.
> Michael
Yes there is. Thanks for the insight !!!
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Session var lost using InProc or StateServer mode

On my development machine my application works fine but on the
deployment server my session variable gets lost after a postback on a
webform. By doing a watch on the Session object I can see that the
SessionId is changing and the mode is StateServer. (I changed from
InProc to StateServer to try to fix the problem but it didn't have any
effect.

Details:
- Win 2k Server/IIS 5.0/.NET Framework 1.1
- I have disabled virus protection.
- The StateServer service is running.

Any ideas are greatly appreciated.

MichaelIs there an underscore character ("_") in the name of your deployment
server? There's a known bug in that case.
--
John Saunders
johnwsaundersiii at hotmail

"MG" <kloodge@.yahoo.com> wrote in message
news:8be4d6f4.0407081008.ed2152f@.posting.google.co m...
> On my development machine my application works fine but on the
> deployment server my session variable gets lost after a postback on a
> webform. By doing a watch on the Session object I can see that the
> SessionId is changing and the mode is StateServer. (I changed from
> InProc to StateServer to try to fix the problem but it didn't have any
> effect.
> Details:
> - Win 2k Server/IIS 5.0/.NET Framework 1.1
> - I have disabled virus protection.
> - The StateServer service is running.
> Any ideas are greatly appreciated.
> Michael
Yes there is. Thanks for the insight !!!

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

session varaibles with asp.net urgent help

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are sameamjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).

2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


3. or try this instead

lblMyname.Text=Session["email"].ToString();
3.
lblAge.Text=Session["Age"].ToString()
its not the Session i wrote small otherwise c # cannot compile. . i have
cancelled the session variable but still cannt display that value in another
page.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
amjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


>
The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).
>
2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


>
>
3. or try this instead
>
lblMyname.Text=Session["email"].ToString();
>
>


where have you cancelled/cleared the session?
when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
3.
lblAge.Text=Session["Age"].ToString()
>
>


amjad wrote:

Quote:

Originally Posted by

when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.
>
>
"nasirmajor@.yahoo.com" wrote:
>

Quote:

Originally Posted by


3.
lblAge.Text=Session["Age"].ToString()


where ever if you have used session.clear or session.removeall replace
it with
session.abondon();
try whats happen?

Session Variable

Hello,
Could someone tell me how to check if a session variable exists and if
not to create it.
Thanks,
MiguelSession["abc"] will return null if abc doesn't exist.
Session["abc"] = 123 will write abc to the session even if it didn't exist
there before.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"shapper" <mdmoura@.gmail.com> wrote in message
news:1173354277.199378.128980@.j27g2000cwj.googlegroups.com...
> Hello,
> Could someone tell me how to check if a session variable exists and if
> not to create it.
> Thanks,
> Miguel
>
if (Session["MyVar"] == null)
Session["MyVar"] = "hello";
"shapper" <mdmoura@.gmail.com> wrote in message
news:1173354277.199378.128980@.j27g2000cwj.googlegroups.com...
> Hello,
> Could someone tell me how to check if a session variable exists and if
> not to create it.
> Thanks,
> Miguel
>

Session Variable

If I have a Session variable such as Session("Id") which is a long, do I
have to convert it before assigning it to a long variable?
Dim nId As Long
nId = Session("Id")On 7/20/2004 10:01 PM, William Gower wrote:

> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")
>
Only if you have Option Explicit on (which I highly recommend; see the
Properties of your project)...otherwise at runtime it will convert it
and if it's invalid, you'll get a format exception...
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7/20/2004 10:59 PM, Craig Deelsnyder wrote:

> On 7/20/2004 10:01 PM, William Gower wrote:
>
> Only if you have Option Explicit on (which I highly recommend; see the
> Properties of your project)...otherwise at runtime it will convert it
> and if it's invalid, you'll get a format exception...
>
sorry, I meant Option Strict...
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Yes, at least if you have Option Strict on (which you should). If you
know in advance that the Session variable holds a Long (and never
anything else), you can use DirectCast to maximize performance:
Dim nId As Long
If Session("Id") Is Nothing Then
' Session has expired, or session variable was never set.
Else
nId = DirectCast(Session("Id"), Long)
End If
"William Gower" <w_gower@.hotmail.com> wrote in message news:<uh43d6sbEHA.2408@.tk2msftngp13.
phx.gbl>...
> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

session variable

Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and logout.aspx.

In logout.aspx i have put following code...
Session.Clear()

Session.RemoveAll()

Session.Abandon()

Response.Redirect("default.aspx")

In Index.aspx I have following code in page load event..

If Session("login") = "" Then 'this session variable is created from default.aspx on successful login which store user login name

Response.Redirect("default.aspx")

End If

But somehow after hitting logout link from index.aspx it still keeps session("login") value though it redirect to default.aspx..

After tht if i try to execute page directly index.aspx (on same browser window), the page index.aspx is displayed..(which is basically should not be displayed.) ...When I hit refresh it redirects to default.aspx but url remains the same with index.aspx

Below is web.config snippet...

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/
Anyone has any clue why its happening like this??

Any help would be appreciated..

Thanx in advance

daveA couple comments. First off, you might save yourself a handful of lines of code as well as this problem if you used the built-in FormsAuthentication:
http://www.15seconds.com/issue/020220.htm
http://www.15seconds.com/issue/020305.htm

I suspect they are getting to index.aspx because the page is cached...hence when they force a refresh they are being logged out. You might want to look at :
http://www.15seconds.com/issue/010202.htm
which will tell you how to make sure the browser doesn't cache the page.

As for why ur session doesn't clear, you might wanna try Response.Redirect("default.aspx", false) If that works check out :
http://weblogs.asp.net/bleroy/archi.../03/207486.aspx for why...not sure if that applies to clearing session though, don't think so.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!)

"dave" <nojunk@.nojunk.com> wrote in message news:ONMZBDbvFHA.2072@.TK2MSFTNGP14.phx.gbl...
Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and logout.aspx.

In logout.aspx i have put following code...
Session.Clear()

Session.RemoveAll()

Session.Abandon()

Response.Redirect("default.aspx")

In Index.aspx I have following code in page load event..

If Session("login") = "" Then 'this session variable is created from default.aspx on successful login which store user login name

Response.Redirect("default.aspx")

End If

But somehow after hitting logout link from index.aspx it still keeps session("login") value though it redirect to default.aspx..

After tht if i try to execute page directly index.aspx (on same browser window), the page index.aspx is displayed..(which is basically should not be displayed.) ...When I hit refresh it redirects to default.aspx but url remains the same with index.aspx

Below is web.config snippet...

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/
Anyone has any clue why its happening like this??

Any help would be appreciated..

Thanx in advance

dave
"dave" <nojunk@.nojunk.com> wrote in message news:ONMZBDbvFHA.2072@.TK2MSFTNGP14.phx.gbl...
Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and logout.aspx.

In logout.aspx i have put following code...
Session.Clear()

Session.RemoveAll()

Session.Abandon()

Response.Redirect("default.aspx")

In Index.aspx I have following code in page load event..

If Session("login") = "" Then 'this session variable is created from default.aspx on successful login which store user login name

Response.Redirect("default.aspx")

End If

In C# I would not check for an empty string, but for null. In VB you might need to
check for "Nothing".
You don't store "strings" in Session, you store "objects". A string is a perfectly
valid object, so you can store it without problems. But if the Session variable
has been removed, it's *removed* (not there, nothing), not an empty string.
But somehow after hitting logout link from index.aspx it still keeps session("login") value though it redirect to default.aspx..

After tht if i try to execute page directly index.aspx (on same browser window), the page index.aspx is displayed..(which is basically should not be displayed.) ...When I hit refresh it redirects to default.aspx but url remains the same with index.aspx

If you use Redirect, you instruct the browser to go to a different URL, so that other
URL should be displayed (If you had used Transfer, this would not be the case, as that
works entirely server-side). So you are not "redirected" to default.aspx, but something else
happened.

Hans Kesting

Session Variable

Hi

In my ASP.NET project, I have a session variable that is assigned on a login page. In another .cs file (in another directory), I'm trying to use
if((string)Session["variable"] == "something"

When I compile, it tells me that Session does not exist in the calss or namespace

My hypothesis is that it is because this directory is compiled before the directory that actually has the Session variable's declaration. Any ideas on how to fix this

thanks

George"Session" is not a global variable, it is a property of the
System.Web.UI.Page object.
When you use Session["variable"] inside an aspx page, it is actually
translating to this.Session["variable"].
When you are in another class which is not an aspx page derived off of the
Page class, it has no access to the Session object.

You either need to pass a reference to the Session object into your other
class (yuck), or pass the value itself as a parameter/property/etc.

--
Michael J. Mooney
MCP+SB, MCAD, MCSD
"George" <anonymous@.discussions.microsoft.com> wrote in message
news:CE2AB820-0B7C-43E0-BCA6-E3A654E6E18A@.microsoft.com...
> Hi,
> In my ASP.NET project, I have a session variable that is assigned on a
login page. In another .cs file (in another directory), I'm trying to use
> if((string)Session["variable"] == "something")
> When I compile, it tells me that Session does not exist in the calss or
namespace.
> My hypothesis is that it is because this directory is compiled before the
directory that actually has the Session variable's declaration. Any ideas
on how to fix this?
> thanks.
> George
Or you can grab the application object and then access the session:

using System.Web; //Need this at top

HttpApplication ha = HttpContext.Current.ApplicationInstance;

string mySessionValue = ha.Session["MySessionValue"];

Very simple:

VB.NET

Dim ha As HttpApplication = HttpContext.Current.ApplicationInstance
Dim mySessionValue As String = ha.Session("MySessionValue")

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Michael J. Mooney" <mike_mooney@._yahoo.com.NOSPAM> wrote in message
news:%23tyjDyLTEHA.2336@.TK2MSFTNGP10.phx.gbl...
> "Session" is not a global variable, it is a property of the
> System.Web.UI.Page object.
> When you use Session["variable"] inside an aspx page, it is actually
> translating to this.Session["variable"].
> When you are in another class which is not an aspx page derived off of the
> Page class, it has no access to the Session object.
> You either need to pass a reference to the Session object into your other
> class (yuck), or pass the value itself as a parameter/property/etc.
> --
> Michael J. Mooney
> MCP+SB, MCAD, MCSD
> "George" <anonymous@.discussions.microsoft.com> wrote in message
> news:CE2AB820-0B7C-43E0-BCA6-E3A654E6E18A@.microsoft.com...
> > Hi,
> > In my ASP.NET project, I have a session variable that is assigned on a
> login page. In another .cs file (in another directory), I'm trying to use
> > if((string)Session["variable"] == "something")
> > When I compile, it tells me that Session does not exist in the calss or
> namespace.
> > My hypothesis is that it is because this directory is compiled before
the
> directory that actually has the Session variable's declaration. Any ideas
> on how to fix this?
> > thanks.
> > George

Session variable

Hello,

I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is loaded.
Can this be done? If yes, how? Thank you in advance and your help is greatly
appreciated.Uytkownik "James" <james@.nodomain.netnapisa w wiadomoci
news:%23orOxZppGHA.3324@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hello,
>
>
I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is
loaded. Can this be done? If yes, how? Thank you in advance and your help
is greatly appreciated.


For me there is only one solution. On the second page in Page_Load method
change this variable.

--
JS
BRE Bank Dev Team, Poland
You would put all the code in the server-side button click handler. e.g.,

Session["myValue"]="new value";
Response.Write("<script>window.Open("hewpage.aspx");</script>");

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"James" wrote:

Quote:

Originally Posted by

Hello,
>
>
I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is loaded.
Can this be done? If yes, how? Thank you in advance and your help is greatly
appreciated.
>
>
>


It's good to know people who know what they are doing!

Thanks, it worked great!

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.comwrote in message
news:F6B66951-B4B5-4F69-A709-F163BA74EAA1@.microsoft.com...

Quote:

Originally Posted by

You would put all the code in the server-side button click handler. e.g.,
>
Session["myValue"]="new value";
Response.Write("<script>window.Open("hewpage.aspx");</script>");
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"James" wrote:
>

Quote:

Originally Posted by

>Hello,
>>
>>
>I have a form with a button that opens a new browser with another form. I
>want to be able to change a session variable before the new form is
>loaded.
>Can this be done? If yes, how? Thank you in advance and your help is
>greatly
>appreciated.
>>
>>
>>

Session Variable

If I have a Session variable such as Session("Id") which is a long, do I
have to convert it before assigning it to a long variable?

Dim nId As Long
nId = Session("Id")On 7/20/2004 10:01 PM, William Gower wrote:

> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

Only if you have Option Explicit on (which I highly recommend; see the
Properties of your project)...otherwise at runtime it will convert it
and if it's invalid, you'll get a format exception...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7/20/2004 10:59 PM, Craig Deelsnyder wrote:

> On 7/20/2004 10:01 PM, William Gower wrote:
>> If I have a Session variable such as Session("Id") which is a long, do I
>> have to convert it before assigning it to a long variable?
>>
>> Dim nId As Long
>> nId = Session("Id")
>>
>>
> Only if you have Option Explicit on (which I highly recommend; see the
> Properties of your project)...otherwise at runtime it will convert it
> and if it's invalid, you'll get a format exception...
sorry, I meant Option Strict...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Yes, at least if you have Option Strict on (which you should). If you
know in advance that the Session variable holds a Long (and never
anything else), you can use DirectCast to maximize performance:

Dim nId As Long
If Session("Id") Is Nothing Then
' Session has expired, or session variable was never set.
Else
nId = DirectCast(Session("Id"), Long)
End If

"William Gower" <w_gower@.hotmail.com> wrote in message news:<uh43d6sbEHA.2408@.tk2msftngp13.phx.gbl>...
> If I have a Session variable such as Session("Id") which is a long, do I
> have to convert it before assigning it to a long variable?
> Dim nId As Long
> nId = Session("Id")

Session Variable

Hello...

I have a simple problem...when I create a session variable as such:

Session("ID") = 1

and read this varaible from time to time...

The problem is that it is shared by all users not just the user that
created the session variable...

That is, if another user logs on and sets

Session("ID") = 2

then this will change the value if Session("ID") for the first
user...

What I want is to have different ID's for each user...

Can someone elxplain what is wrong?

Thanks...It shouldn't happen and I've never seent that. Are you sure this is
System.Web.HttpContext.Current.Session and not some other cusom session
object. You can also dump the SessionID to see if this is the same value (is
this hardcoded somewhere ?). What if you do a bare bone sample that shoes
that in your dev server on a bare bone site. Do you have the same problem ?

Ah ! Do you open another window and test to check this ? Note that when you
open another window (without relancunhing i..e) the new window uses the same
session.

--
Patrice

"Flurry" <cj406168@.stmail.staffs.ac.uka crit dans le message de news:
1189422564.511977.244720@.d55g2000hsg.googlegroups. com...

Quote:

Originally Posted by

Hello...
>
I have a simple problem...when I create a session variable as such:
>
Session("ID") = 1
>
and read this varaible from time to time...
>
The problem is that it is shared by all users not just the user that
created the session variable...
>
That is, if another user logs on and sets
>
Session("ID") = 2
>
then this will change the value if Session("ID") for the first
user...
>
What I want is to have different ID's for each user...
>
Can someone elxplain what is wrong?
>
Thanks...
>


You must be doing something else in your code that you haven't shown, or you
are using another Browser window from the same session, because this is
definitely *not* the expected behavior.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"Flurry" wrote:

Quote:

Originally Posted by

Hello...
>
I have a simple problem...when I create a session variable as such:
>
Session("ID") = 1
>
and read this varaible from time to time...
>
The problem is that it is shared by all users not just the user that
created the session variable...
>
That is, if another user logs on and sets
>
Session("ID") = 2
>
then this will change the value if Session("ID") for the first
user...
>
What I want is to have different ID's for each user...
>
Can someone elxplain what is wrong?
>
Thanks...
>
>


Hello and thank you both for your reply...

This is strange...the code is very simple...I have two aspx pages:-

Page 1 has the following code

System.Web.HttpContext.Current.Session ("Country" ) = countryCode
server.transfer("FOTrans.aspx")

FOTrans.aspx just reads the country code as follows...

countryCode = System.Web.HttpContext.Current.Session("country")

However, as I said before the session variable is shared between
users. I have just tried logging on using two different PC's and the
problem exists. If I set Session("Country") to USA on the first pc
then set it to UK in the second pc, the first pc reads UK not USA...

Any ideas as to what could be wrong?

Thanks...
re:
!System.Web.HttpContext.Current.Session ("Country" ) = countryCode

Where dos the value for countryCode come from ?

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message news:1189430823.328225.66540@.57g2000hsv.googlegrou ps.com...

Quote:

Originally Posted by

Hello and thank you both for your reply...
>
This is strange...the code is very simple...I have two aspx pages:-
>
Page 1 has the following code
>
System.Web.HttpContext.Current.Session ("Country" ) = countryCode
server.transfer("FOTrans.aspx")
>
FOTrans.aspx just reads the country code as follows...
>
countryCode = System.Web.HttpContext.Current.Session("country")
>
However, as I said before the session variable is shared between
users. I have just tried logging on using two different PC's and the
problem exists. If I set Session("Country") to USA on the first pc
then set it to UK in the second pc, the first pc reads UK not USA...
>
Any ideas as to what could be wrong?
>
Thanks...
>
>
>


Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.

Shared countryCode as String.
CountryCode = Session("Country")

I was using the shred variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?

Thanks for your help...
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message
news:1189433300.687467.258850@.50g2000hsm.googlegro ups.com...

Quote:

Originally Posted by

Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.
>
Shared countryCode as String.
CountryCode = Session("Country")
>
I was using the shared variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?


Yes it is. Shared variables in ASP.NET need *extremely* careful
management...

Avoid them if you can...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
re:
!shared variables have scope outside their own session.
!This is right isn't it?

Exactly, and that is why I asked where that value came from.
I suspected you were setting a global variable.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Flurry" <cj406168@.stmail.staffs.ac.ukwrote in message news:1189433300.687467.258850@.50g2000hsm.googlegro ups.com...

Quote:

Originally Posted by

Thanks for your replies...however, I've discovered my mistake...I'm
using a shared variable to hold the Session("Country") e.g.
>
Shared countryCode as String.
CountryCode = Session("Country")
>
I was using the shred variable as a global variable...I just didn't
realise that shared variables have scope outside their own session.
This is right isn't it?
>
Thanks for your help...
>
>

Session Variable

Hello,

Could someone tell me how to check if a session variable exists and if
not to create it.

Thanks,
MiguelSession["abc"] will return null if abc doesn't exist.
Session["abc"] = 123 will write abc to the session even if it didn't exist
there before.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"shapper" <mdmoura@.gmail.comwrote in message
news:1173354277.199378.128980@.j27g2000cwj.googlegr oups.com...

Quote:

Originally Posted by

Hello,
>
Could someone tell me how to check if a session variable exists and if
not to create it.
>
Thanks,
Miguel
>


if (Session["MyVar"] == null)
Session["MyVar"] = "hello";

"shapper" <mdmoura@.gmail.comwrote in message
news:1173354277.199378.128980@.j27g2000cwj.googlegr oups.com...

Quote:

Originally Posted by

Hello,
>
Could someone tell me how to check if a session variable exists and if
not to create it.
>
Thanks,
Miguel
>

Session Variable

Hello,

Does anyone know if it is possible to set a session variable when a user
click on a HyperLink?

Thank

MLHave the page post back, set the session variable and either
Server.Transfer or Response.Redirect
Do you have an example page that show the principle?

Is it possible to do it without involving forms?

Thank

ML
<garethdjames@.gmail.com> wrote in message
news:1116602123.826280.245700@.o13g2000cwo.googlegr oups.com...
> Have the page post back, set the session variable and either
> Server.Transfer or Response.Redirect
can you give me more details of what you want to do
Now I'm home and cannot see VS.Net, therefore I write what I remember, and
hope I don't tell you wrong things.
You should use the LinkButton whick looks similar to the HyperLink, and in
the Click event you can set the session variable and then link with:

Page.Response.Redirect("target.aspx");

--
Vanni Tomezzoli
S. Donato Mil., Milano, Italy
vannto@.tin.it
http://xoomer.virgilio.it/vtomezzo

"Michel Lapointe" <a@.a.com> ha scritto nel messaggio
news:u$x7N0UXFHA.1152@.tk2msftngp13.phx.gbl...
> Hello,
> Does anyone know if it is possible to set a session variable when a
user
> click on a HyperLink?
> Thank
> ML

Session Variable

Hello,
Does anyone know if it is possible to set a session variable when a user
click on a HyperLink?
Thank
MLHave the page post back, set the session variable and either
Server.Transfer or Response.Redirect
Do you have an example page that show the principle?
Is it possible to do it without involving forms?
Thank
ML
<garethdjames@.gmail.com> wrote in message
news:1116602123.826280.245700@.o13g2000cwo.googlegroups.com...
> Have the page post back, set the session variable and either
> Server.Transfer or Response.Redirect
>
can you give me more details of what you want to do
Now I'm home and cannot see VS.Net, therefore I write what I remember, and
hope I don't tell you wrong things.
You should use the LinkButton whick looks similar to the HyperLink, and in
the Click event you can set the session variable and then link with:
Page.Response.Redirect("target.aspx");
Vanni Tomezzoli
S. Donato Mil., Milano, Italy
vannto@.tin.it
http://xoomer.virgilio.it/vtomezzo
"Michel Lapointe" <a@.a.com> ha scritto nel messaggio
news:u$x7N0UXFHA.1152@.tk2msftngp13.phx.gbl...
> Hello,
> Does anyone know if it is possible to set a session variable when a
user
> click on a HyperLink?
> Thank
> ML
>

session variable

Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and lo
gout.aspx.
In logout.aspx i have put following code...
Session.Clear()
Session.RemoveAll()
Session.Abandon()
Response.Redirect("default.aspx")
In Index.aspx I have following code in page load event..
If Session("login") = "" Then 'this session variable is created from default
.aspx on successful login which store user login name
Response.Redirect("default.aspx")
End If
But somehow after hitting logout link from index.aspx it still keeps session
("login") value though it redirect to default.aspx..
After tht if i try to execute page directly index.aspx (on same browser wind
ow), the page index.aspx is displayed..(which is basically should not be dis
played.) ...When I hit refresh it redirects to default.aspx but url remains
the same with index.aspx
Below is web.config snippet...
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
Anyone has any clue why its happening like this'
Any help would be appreciated..
Thanx in advance
daveA couple comments. First off, you might save yourself a handful of lines of
code as well as this problem if you used the built-in FormsAuthentication:
http://www.15seconds.com/issue/020220.htm
http://www.15seconds.com/issue/020305.htm
I suspect they are getting to index.aspx because the page is cached...hence
when they force a refresh they are being logged out. You might want to look
at :
http://www.15seconds.com/issue/010202.htm
which will tell you how to make sure the browser doesn't cache the page.
As for why ur session doesn't clear, you might wanna try Response.Redirect("
default.aspx", false) If that works check out :
http://weblogs.asp.net/bleroy/archi.../03/207486.aspx for why...not
sure if that applies to clearing session though, don't think so.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!
)
"dave" <nojunk@.nojunk.com> wrote in message news:ONMZBDbvFHA.2072@.TK2MSFTNGP
14.phx.gbl...
Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and lo
gout.aspx.
In logout.aspx i have put following code...
Session.Clear()
Session.RemoveAll()
Session.Abandon()
Response.Redirect("default.aspx")
In Index.aspx I have following code in page load event..
If Session("login") = "" Then 'this session variable is created from default
.aspx on successful login which store user login name
Response.Redirect("default.aspx")
End If
But somehow after hitting logout link from index.aspx it still keeps session
("login") value though it redirect to default.aspx..
After tht if i try to execute page directly index.aspx (on same browser wind
ow), the page index.aspx is displayed..(which is basically should not be dis
played.) ...When I hit refresh it redirects to default.aspx but url remains
the same with index.aspx
Below is web.config snippet...
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
Anyone has any clue why its happening like this'
Any help would be appreciated..
Thanx in advance
dave
"dave" <nojunk@.nojunk.com> wrote in message news:ONMZBDbvFHA.2072@.TK2MSFTNGP
14.phx.gbl...
Hi all
I'm newbie to asp.net and building simple pages using vb.net.
I have got three pages default.aspx (which is login page), index.aspx and lo
gout.aspx.
In logout.aspx i have put following code...
Session.Clear()
Session.RemoveAll()
Session.Abandon()
Response.Redirect("default.aspx")
In Index.aspx I have following code in page load event..
If Session("login") = "" Then 'this session variable is created from default
.aspx on successful login which store user login name
Response.Redirect("default.aspx")
End If
In C# I would not check for an empty string, but for null. In VB you might n
eed to
check for "Nothing".
You don't store "strings" in Session, you store "objects". A string is a per
fectly
valid object, so you can store it without problems. But if the Session varia
ble
has been removed, it's *removed* (not there, nothing), not an empty string.
But somehow after hitting logout link from index.aspx it still keeps session
("login") value though it redirect to default.aspx..
After tht if i try to execute page directly index.aspx (on same browser wind
ow), the page index.aspx is displayed..(which is basically should not be dis
played.) ...When I hit refresh it redirects to default.aspx but url remains
the same with index.aspx
If you use Redirect, you instruct the browser to go to a different URL, so t
hat other
URL should be displayed (If you had used Transfer, this would not be the cas
e, as that
works entirely server-side). So you are not "redirected" to default.aspx, bu
t something else
happened.
Hans Kesting

Session Variable

Hi,
In my ASP.NET project, I have a session variable that is assigned on a login
page. In another .cs file (in another directory), I'm trying to use
if((string)Session["variable"] == "something")
When I compile, it tells me that Session does not exist in the calss or name
space.
My hypothesis is that it is because this directory is compiled before the di
rectory that actually has the Session variable's declaration. Any ideas on
how to fix this?
thanks.
George"Session" is not a global variable, it is a property of the
System.Web.UI.Page object.
When you use Session["variable"] inside an aspx page, it is actually
translating to this.Session["variable"].
When you are in another class which is not an aspx page derived off of the
Page class, it has no access to the Session object.
You either need to pass a reference to the Session object into your other
class (yuck), or pass the value itself as a parameter/property/etc.
Michael J. Mooney
MCP+SB, MCAD, MCSD
"George" <anonymous@.discussions.microsoft.com> wrote in message
news:CE2AB820-0B7C-43E0-BCA6-E3A654E6E18A@.microsoft.com...
> Hi,
> In my ASP.NET project, I have a session variable that is assigned on a
login page. In another .cs file (in another directory), I'm trying to use
> if((string)Session["variable"] == "something")
> When I compile, it tells me that Session does not exist in the calss or
namespace.
> My hypothesis is that it is because this directory is compiled before the
directory that actually has the Session variable's declaration. Any ideas
on how to fix this?
> thanks.
> George
Or you can grab the application object and then access the session:
using System.Web; //Need this at top
HttpApplication ha = HttpContext.Current.ApplicationInstance;
string mySessionValue = ha.Session["MySessionValue"];
Very simple:
VB.NET
Dim ha As HttpApplication = HttpContext.Current.ApplicationInstance
Dim mySessionValue As String = ha.Session("MySessionValue")
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
****************************************
********
Think Outside the Box!
****************************************
********
"Michael J. Mooney" <mike_mooney@._yahoo.com.NOSPAM> wrote in message
news:%23tyjDyLTEHA.2336@.TK2MSFTNGP10.phx.gbl...
> "Session" is not a global variable, it is a property of the
> System.Web.UI.Page object.
> When you use Session["variable"] inside an aspx page, it is actually
> translating to this.Session["variable"].
> When you are in another class which is not an aspx page derived off of the
> Page class, it has no access to the Session object.
> You either need to pass a reference to the Session object into your other
> class (yuck), or pass the value itself as a parameter/property/etc.
> --
> Michael J. Mooney
> MCP+SB, MCAD, MCSD
> "George" <anonymous@.discussions.microsoft.com> wrote in message
> news:CE2AB820-0B7C-43E0-BCA6-E3A654E6E18A@.microsoft.com...
> login page. In another .cs file (in another directory), I'm trying to use
> namespace.
the
> directory that actually has the Session variable's declaration. Any ideas
> on how to fix this?
>

Session Variable

I'm using on my shopping cart a session variable to store all products that user have put in to the cart.
The script that I use is writen from a book that I bought. I managed to edit the script so that It suites me.
But I have a problem., The book don't tell how to do the checkoutfunction. How can I get all values from the session variable and storethem to my database.
Major problem is that I don't know how to do the for loop that shouldreed the session variable and give value to the parameters.
Session variable (cart) have following variables stored (cartid:integer, PID:integer , PAKID:Integer , Productname:String , Quantity:integer ,Price:Decimal)
Please Help me with this.
If you download the source code for the Commerce Starter Kit from the "Starter Kits" tab on this web site, it has a great example on how to handle storing items in a shopping cart, and then handling the checkout.
smtraber
It's prity big I'm not so good at coding. I have mostly of my time used Dreamweaver.


<%
For Each Cartid in Session("cart")
       Response.Write cartid & "=" & Session("cart") & "<br>"
Next
%>
Wuold this work to print the cartid in the session cart.
I have in the session following strings also: PID,PAKID,quantity all integer and price as decimal and productname as string
How should I insert the code into this for each loop so I would get value of all the variables in the session varibale

Session variable - no cookies

Hi;

I need to keep a string in Session["name"] however this does not work if the
user has cookies turned off. How can I work around this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htmYou should use cookieless session... Then you do not have to worry about
user cookie settings.
asp.net needs browser cookie settings to be turned on to store the session
ID, which is the default setting.. But if you go into the web.config and set
cookieless=true, then asp.net will embed the session id in the url and will
make your application independent of browser cookie settings.

"David Thielen" <thielen@.nospam.nospamwrote in message
news:11A2BCCE-2E10-40C9-A0F7-18DFE6DB79C0@.microsoft.com...

Quote:

Originally Posted by

Hi;
>
I need to keep a string in Session["name"] however this does not work if
the
user has cookies turned off. How can I work around this?
>
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
>
Cubicle Wars - http://www.windwardreports.com/film.htm
>
>


Hi;

Reading this it looks like you are either always cookieless or always
cookie(?) but can't have it go cookieless only if necessary. I'd rather not
have the cookie always in the url for the occasional paranoid who doesn't
allow session cookies.

So...

Is there a way to determine if cookies are allowed and put up some text in
the web page if they are turned off?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm
"Kumar Reddi" wrote:

Quote:

Originally Posted by

You should use cookieless session... Then you do not have to worry about
user cookie settings.
asp.net needs browser cookie settings to be turned on to store the session
ID, which is the default setting.. But if you go into the web.config and set
cookieless=true, then asp.net will embed the session id in the url and will
make your application independent of browser cookie settings.
>
"David Thielen" <thielen@.nospam.nospamwrote in message
news:11A2BCCE-2E10-40C9-A0F7-18DFE6DB79C0@.microsoft.com...

Quote:

Originally Posted by

Hi;

I need to keep a string in Session["name"] however this does not work if
the
user has cookies turned off. How can I work around this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
Cubicle Wars - http://www.windwardreports.com/film.htm


>
>
>


Hi David,

You are right that you will have to be always cookieless or always cookie.
Setting cookieless="AutoDetect" will only use the browser capabilities, if
user disabled cookies, cookies still will be used by not working.

One way to determine whether cookies are accepted is by trying to write a
cookie and then trying to read it back again. If you cannot read the cookie
you wrote, you assume that cookies are turned off in the browser.

For complete code listing, please see following MSDN Library:

#ASP.NET Cookies Overview
http://msdn2.microsoft.com/en-us/library/ms178194.aspx
(Search for section titled "Determining Whether a Browser Accepts Cookies")

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...rt/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Session Variable

I have an application where the default page requires the user to choose the location they are logging into. I take the value (one or two letter designation) and save it to a Session variable. I then access this variable on the page load of all pages in the application and use the value to call stored procedures to display the proper data from the database. The problem is, some users are timing out and lose their session causing them to have to go back to the first page and re-choose their location. I did increase the session timeout to 60 but this may still not be long enough for some users. Is there a better way to do this without using a session variable? Any help and/or example VB code will be appreciated.

Thanks

While navigating to other page assign this value to a hidden field. Then afterwards check the value of hidden field instead of Session variable. Once you are navigating to another page transfer this value in hidden field again to Session.

Let me know if you need any further help


Any session var or app var would be subject to a session timeout. You do not want to extend the timeout too much because it has an adverse effect in resource consumption.

If your security requirements are not too stringent (risk is low), you could use a QueryString (URL) parameter instead. Validate the parameter to make sure nothing fishy comes in before you use it. You could keep the info in a user database and get the data from there when the user first logs in.


Forgot: You could also use Hidden fields (if security is not stringent) or cokkies if accepted in your client browsers.

See:http://msdn2.microsoft.com/en-us/library/z1hkazw7.aspx


I tried the suggestion and am now running into a problem. It works great if the user stays on the same page. The problem is when the user clicks on another page using the link buttons I provide. If the session expires then my variables are not set. I was hoping to set the Session Variables again when the user leaves the page but I'm not sure where to do this. Any more ideas?

What I would recommend is that you use a cookie for your application with a time-out of however many minutes you think you need. Each page would then check the cookie to get the values needed. With those wonderful people, such as myself, that don't allow most cookies, you can always make the page auto-refresh every x number of minutes. That should reset the timer on the session variable. You will have the problem of needing to make sure that data is not resubmitted. Web applications have the drawback of not automatically trusting the user the way a desktop application would.

Session variable

Hello,
How to declare a variable of session without value (empty) ?
Because If I use a page with a Null Session I have the error :
"Object reference not set to an instance of an object."
on this line :
Line 16: Dim SessionUser As String = Session("USER").ToString

Thank you for your help.
PAB.You can use String.Empty for string values
Hello,
Thanks, I try that.
PAB.
C#

if ( Session["User"] == null)
{

// not exists

}

VB.Net

IF SESSION["USER"] is Nothing THEN

// Not Exists.

END IF