Showing posts with label login. Show all posts
Showing posts with label login. Show all posts

Saturday, March 31, 2012

Session time-out,when the page breaks?

Hi..

I had published a website in the server( I am using VS 2005,ASP.NET2.0, With C#) . I tried testing the site by asking several users to login to the website and do unit testing. At one instance of time, the page breaks for a particular user. When the page breaks, the other users who are tesing in their machine are getting a session time-out and are forced to log out.

Why is such a session-time out issue happening, when one of the users page breaks. I have set the session variable to 20 minutes,which is the default. But what's confusing is , when one of the user's page breaks, the others get a session time-out? Why is such a session-time out occuring?

Please help.

Thanks.

What do you mean when you say "the page breaks?" If an app pool cycles you might see this effect. Have you diagnosed the "page break" to see what happens?

Jeff


Thank you very much for the reply.

The page break, I referred is the page crashing(asp.net error page) .I have customized the error page to show, An Unexpected error occurred, please try after some time.

But when the user tries the same steps to find the page crash, he is not able to, as the page works well. This is a kind of absurd. The page is not crashing always, but it is random. I checked the log, but it was not providing much information. I also could not re-trace the page crash, as the page worked well.

But why is the session getting timed out for the other users, when one of the users page crashes?

Thanks.


Hi..

I am sorry that I forgot to include a scenario in my web page,which i am doing. I have written a code to delete a folder in the session end in global.asax. When i commented the code, and tried testing, the session time out was not occuring.

I searched in the google, and came out with this:

http://www.velocityreviews.com/forums/t116975-all-session-are-getting-down-when-i-delete-sessions-folders.html

Is this the reason for all sessions getting timed-out, when a page crashes?

Thanks


Hi Venkatzeus,

As far as i know, if you delete a folder which is in your application directory, the appDomain will restart, and you will lose your session.

I hope this helps.


This happens as your worker process memory limits get full and asp.net worker process gets restarted. how to do this setting you can find at

http://www.asp.net/faq/AspNetAndIIS6.aspx

But I think you needs to findout why its getting full.

When you get this error check server CPU Usage what it shows?

then debug.


HI,,

Thank you very much for the reply. I will try with it and provide the results.

Thanks

Session Timeout..

When the session times out, I would like to navigate to the login page.
Currently when the session times out, the displayed screen remains visible
on the screen however when the user clicks on the screen will take to the
login page.

How to do that?

BenjaminYou could try using the javascript setTimeout function set to 20 minutes
(the default session timeout period) and then set the
document.location.href='login.aspx' via client side code.
Here's an example of using the javascript setTimeout function:
http://www.crowes.f9.co.uk/Javascript/timer.htm

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

"Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
news:%23%23YjkXrmEHA.3608@.TK2MSFTNGP09.phx.gbl...
> When the session times out, I would like to navigate to the login page.
> Currently when the session times out, the displayed screen remains visible
> on the screen however when the user clicks on the screen will take to the
> login page.
> How to do that?
> Benjamin
Hi i had the same problem.
Buti fixed..
If u need a more detailed script let me know!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Yes, I need to know.
Benjamin

"naijacoder naijacoder" <naijacoder@.toughguy.net> wrote in message
news:eu0aGPsmEHA.3988@.tk2msftngp13.phx.gbl...
> Hi i had the same problem.
> Buti fixed..
> If u need a more detailed script let me know!
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
But what do you really want to do?

"Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
news:eFTtrasmEHA.2908@.TK2MSFTNGP12.phx.gbl...
> Yes, I need to know.
> Benjamin
> "naijacoder naijacoder" <naijacoder@.toughguy.net> wrote in message
> news:eu0aGPsmEHA.3988@.tk2msftngp13.phx.gbl...
> > Hi i had the same problem.
> > Buti fixed..
> > If u need a more detailed script let me know!
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!
Steve gave you the answer. In more detail:

Session times out (by default) 20 minutes after the last Request was
received by the client browser instance holding that SessionID in a
temporary cookie. As no request is received on the server, no response can
be sent to the client. Therefore, the redirect MUST occur on the client.
That means JavaScript. And that means that your JavaScript function should
fire just as the Session times out (20 minutes). You would use the
JavaScript setTimeOut() function to accomplish this.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
news:eFTtrasmEHA.2908@.TK2MSFTNGP12.phx.gbl...
> Yes, I need to know.
> Benjamin
> "naijacoder naijacoder" <naijacoder@.toughguy.net> wrote in message
> news:eu0aGPsmEHA.3988@.tk2msftngp13.phx.gbl...
> > Hi i had the same problem.
> > Buti fixed..
> > If u need a more detailed script let me know!
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!
Thanks for your answers.

Now I understand I have to use setTimeout to achieve my goal.

The link http://www.crowes.f9.co.uk/Javascript/timer.htm is really helpful.

Which client side event I should use to keep track the user is still using
the website.

Thanks,

Benjamin

"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:#lv4LermEHA.324@.TK2MSFTNGP11.phx.gbl...
> You could try using the javascript setTimeout function set to 20 minutes
> (the default session timeout period) and then set the
> document.location.href='login.aspx' via client side code.
> Here's an example of using the javascript setTimeout function:
> http://www.crowes.f9.co.uk/Javascript/timer.htm
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
> "Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
> news:%23%23YjkXrmEHA.3608@.TK2MSFTNGP09.phx.gbl...
> > When the session times out, I would like to navigate to the login page.
> > Currently when the session times out, the displayed screen remains
visible
> > on the screen however when the user clicks on the screen will take to
the
> > login page.
> > How to do that?
> > Benjamin
Also I would like to inform the user just before X seconds of page expiry. I
do not want to use alert(). Is it possible to display the message on the
tool bar as once the count down for expire starts.

Thanks,

Benjamin

"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:#lv4LermEHA.324@.TK2MSFTNGP11.phx.gbl...
> You could try using the javascript setTimeout function set to 20 minutes
> (the default session timeout period) and then set the
> document.location.href='login.aspx' via client side code.
> Here's an example of using the javascript setTimeout function:
> http://www.crowes.f9.co.uk/Javascript/timer.htm
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
> "Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
> news:%23%23YjkXrmEHA.3608@.TK2MSFTNGP09.phx.gbl...
> > When the session times out, I would like to navigate to the login page.
> > Currently when the session times out, the displayed screen remains
visible
> > on the screen however when the user clicks on the screen will take to
the
> > login page.
> > How to do that?
> > Benjamin
The browser will keep track of that for you.
All you need is one client side event to fire once the trigger time has
elapsed and you want to warn the user.
You can name the event anything you want.

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

"Benjamin" <BenSmithNg@.hotmail.com> wrote in message
news:uan1PfQnEHA.392@.tk2msftngp13.phx.gbl...
> Thanks for your answers.
> Now I understand I have to use setTimeout to achieve my goal.
> The link http://www.crowes.f9.co.uk/Javascript/timer.htm is really
> helpful.
> Which client side event I should use to keep track the user is still using
> the website.
> Thanks,
> Benjamin
>
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:#lv4LermEHA.324@.TK2MSFTNGP11.phx.gbl...
>> You could try using the javascript setTimeout function set to 20 minutes
>> (the default session timeout period) and then set the
>> document.location.href='login.aspx' via client side code.
>> Here's an example of using the javascript setTimeout function:
>> http://www.crowes.f9.co.uk/Javascript/timer.htm
>>
>> --
>> I hope this helps,
>> Steve C. Orr, MCSD, MVP
>> http://Steve.Orr.net
>>
>>
>> "Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
>> news:%23%23YjkXrmEHA.3608@.TK2MSFTNGP09.phx.gbl...
>> > When the session times out, I would like to navigate to the login page.
>> > Currently when the session times out, the displayed screen remains
> visible
>> > on the screen however when the user clicks on the screen will take to
> the
>> > login page.
>>> > How to do that?
>>> > Benjamin
>>>>
>>
Yes you can display a message to the status bar of the browser.
Here's a nice example:
http://simplythebest.net/scripts/DH...ascript_58.html

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

"Benjamin" <BenSmithNg@.hotmail.com> wrote in message
news:uGdHQhQnEHA.3520@.TK2MSFTNGP11.phx.gbl...
> Also I would like to inform the user just before X seconds of page expiry.
> I
> do not want to use alert(). Is it possible to display the message on the
> tool bar as once the count down for expire starts.
> Thanks,
> Benjamin
>
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:#lv4LermEHA.324@.TK2MSFTNGP11.phx.gbl...
>> You could try using the javascript setTimeout function set to 20 minutes
>> (the default session timeout period) and then set the
>> document.location.href='login.aspx' via client side code.
>> Here's an example of using the javascript setTimeout function:
>> http://www.crowes.f9.co.uk/Javascript/timer.htm
>>
>> --
>> I hope this helps,
>> Steve C. Orr, MCSD, MVP
>> http://Steve.Orr.net
>>
>>
>> "Benjamin Smith" <BenSmithNg@.hotmail.com> wrote in message
>> news:%23%23YjkXrmEHA.3608@.TK2MSFTNGP09.phx.gbl...
>> > When the session times out, I would like to navigate to the login page.
>> > Currently when the session times out, the displayed screen remains
> visible
>> > on the screen however when the user clicks on the screen will take to
> the
>> > login page.
>>> > How to do that?
>>> > Benjamin
>>>>
>>

Session Timeout.

Friends,
We have a simple application which has login page, users login to it
and enter their contact details and all other stuff. It is working
fine. Now we have moved to new windows 2003 server. The page works
but it gets refreshed every 5 mintues and goes back to login.aspx page.
How do I fix this.
Thanks for any help.
KAdd this in your Web.config file to elongate Session to 60min for example:
<sessionState cookieless="UseCookies" mode="InProc" timeout="60" />
but add it between
<system.web> </system.web>
--
Bishoy George
bishoy@.bishoy.com
20102550399
"Sai" <kumar877@.gmail.com> wrote in message
news:1145074352.770881.44720@.u72g2000cwu.googlegroups.com...
> Friends,
> We have a simple application which has login page, users login to it
> and enter their contact details and all other stuff. It is working
> fine. Now we have moved to new windows 2003 server. The page works
> but it gets refreshed every 5 mintues and goes back to login.aspx page.
> How do I fix this.
> Thanks for any help.
> K
>
no that did not help. same thing is happening again.
Do you have code in your page to redirect to your login page? Sounds like
your session is timing out and your code is kicking in to repost. Write some
code in your session_end event handler to dump a file with a time-stamp to
tell you when the session is dying. You can trouble-shoot from there.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145116360.101576.258960@.i40g2000cwc.googlegroups.com...
> no that did not help. same thing is happening again.
>
Hi Alvin,
thanks for the advise. Iam inputting the values to a text file when
session times out. It is coming as 60 seconds. So the session is
timing out at every 60 seconds, but I could not find where to change
these value. I checked the web.config and machine.config and
application pools .
Let me know specific place to change this value.
thanks,
K
So you have an override somewhere in your code because the timeout value is
20 minutes by default. Search your code for that value. Alternatively, it
may be overridden in the web.config file. As a quick test, you can set
session.timeout = 10 minutes. It should stick otherwise, you have something
funky going on in your app that you either don't know about or aren't
sharing.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145288352.456543.4650@.t31g2000cwb.googlegroups.com...
> Hi Alvin,
> thanks for the advise. Iam inputting the values to a text file when
> session times out. It is coming as 60 seconds. So the session is
> timing out at every 60 seconds, but I could not find where to change
> these value. I checked the web.config and machine.config and
> application pools .
> Let me know specific place to change this value.
> thanks,
> K
>
Nothing in the code, nothing in the web.config. It has to be some
other place. I have seen all my code and no where I am setting these
values.
I tried changing session timeout to 10 minutes and still nothing
happens. So it got to be some where, not that simple.
Where else it can be.?
Thanks.
K
you need that check. go back and put it in there so that your application
can be resilient to memory issues. However, raise the limit to around 1gig
or so. The reason for this is that the application pool should be recycled
if an errant application (your code) decides to hog memory. Removing that
check prevents detection of this and other conditions.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145306983.181641.177810@.i40g2000cwc.googlegroups.com...
> Thanks for all your help. It got fixed just now. The problem is
> Virtual memory was so low (250MB), so every time a worker process
> initiates it goes to 250 MB and it recycles, so what we did was, we
> just removed the check box next to virtual memory of application pool.
> that's it. It works...great relief.
> Thanks,
> K
>
Thanks for all your help. It got fixed just now. The problem is
Virtual memory was so low (250MB), so every time a worker process
initiates it goes to 250 MB and it recycles, so what we did was, we
just removed the check box next to virtual memory of application pool.
that's it. It works...great relief.
Thanks,
K
Where is the Virtual memory checked/set? Somewhere in IIS?
Ron

Session Timeout.

Friends,

We have a simple application which has login page, users login to it
and enter their contact details and all other stuff. It is working
fine. Now we have moved to new windows 2003 server. The page works
but it gets refreshed every 5 mintues and goes back to login.aspx page.
How do I fix this.

Thanks for any help.

KAdd this in your Web.config file to elongate Session to 60min for example:

<sessionState cookieless="UseCookies" mode="InProc" timeout="60" /
but add it between
<system.web> </system.web>
--

Bishoy George
bishoy@.bishoy.com
20102550399

--------

"Sai" <kumar877@.gmail.com> wrote in message
news:1145074352.770881.44720@.u72g2000cwu.googlegro ups.com...
> Friends,
> We have a simple application which has login page, users login to it
> and enter their contact details and all other stuff. It is working
> fine. Now we have moved to new windows 2003 server. The page works
> but it gets refreshed every 5 mintues and goes back to login.aspx page.
> How do I fix this.
> Thanks for any help.
> K
no that did not help. same thing is happening again.
Do you have code in your page to redirect to your login page? Sounds like
your session is timing out and your code is kicking in to repost. Write some
code in your session_end event handler to dump a file with a time-stamp to
tell you when the session is dying. You can trouble-shoot from there.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"Sai" <kumar877@.gmail.com> wrote in message
news:1145116360.101576.258960@.i40g2000cwc.googlegr oups.com...
> no that did not help. same thing is happening again.
Hi Alvin,

thanks for the advise. Iam inputting the values to a text file when
session times out. It is coming as 60 seconds. So the session is
timing out at every 60 seconds, but I could not find where to change
these value. I checked the web.config and machine.config and
application pools .

Let me know specific place to change this value.

thanks,
K
So you have an override somewhere in your code because the timeout value is
20 minutes by default. Search your code for that value. Alternatively, it
may be overridden in the web.config file. As a quick test, you can set
session.timeout = 10 minutes. It should stick otherwise, you have something
funky going on in your app that you either don't know about or aren't
sharing.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"Sai" <kumar877@.gmail.com> wrote in message
news:1145288352.456543.4650@.t31g2000cwb.googlegrou ps.com...
> Hi Alvin,
> thanks for the advise. Iam inputting the values to a text file when
> session times out. It is coming as 60 seconds. So the session is
> timing out at every 60 seconds, but I could not find where to change
> these value. I checked the web.config and machine.config and
> application pools .
> Let me know specific place to change this value.
> thanks,
> K
Nothing in the code, nothing in the web.config. It has to be some
other place. I have seen all my code and no where I am setting these
values.
I tried changing session timeout to 10 minutes and still nothing
happens. So it got to be some where, not that simple.
Where else it can be.?

Thanks.
K
Thanks for all your help. It got fixed just now. The problem is
Virtual memory was so low (250MB), so every time a worker process
initiates it goes to 250 MB and it recycles, so what we did was, we
just removed the check box next to virtual memory of application pool.
that's it. It works...great relief.

Thanks,
K
you need that check. go back and put it in there so that your application
can be resilient to memory issues. However, raise the limit to around 1gig
or so. The reason for this is that the application pool should be recycled
if an errant application (your code) decides to hog memory. Removing that
check prevents detection of this and other conditions.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"Sai" <kumar877@.gmail.com> wrote in message
news:1145306983.181641.177810@.i40g2000cwc.googlegr oups.com...
> Thanks for all your help. It got fixed just now. The problem is
> Virtual memory was so low (250MB), so every time a worker process
> initiates it goes to 250 MB and it recycles, so what we did was, we
> just removed the check box next to virtual memory of application pool.
> that's it. It works...great relief.
> Thanks,
> K
Where is the Virtual memory checked/set? Somewhere in IIS?

Ron
it's under one of the application pool health monitoring tabs in IIS

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"RonL" <sal_paradise_93@.yahoo.com> wrote in message
news:1145322157.561147.218050@.j33g2000cwa.googlegr oups.com...
> Where is the Virtual memory checked/set? Somewhere in IIS?
> Ron
I couldn't find it. I see you're talking about Windows 2003 and I'm
looking at IIS 5 and XP Pro on my local machine.

Ron
IIS 5 doesn't have these characteristics. sorry.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------

"RonL" <sal_paradise_93@.yahoo.com> wrote in message
news:1145411388.245339.46900@.i40g2000cwc.googlegro ups.com...
>I couldn't find it. I see you're talking about Windows 2003 and I'm
> looking at IIS 5 and XP Pro on my local machine.
> Ron

Session Times Out.... Navigate to Login Page

When the sessions times out I would like to take the user to the login page.
Currently even though session times out user will come to know only when he
clicks on the screen. How to direct the user automatically to login page
once the session times out. I am using .Net Framework 1.1. and IIS 5
AmithYou could force the browser to refresh after a set amount of time:
Response.AppendHeader("Refresh", (Session.Timeout * 60 +
10).ToString() + "; URL=Login.aspx");
This will calculate the time to refresh using the Session timeout
value on the server (specified in minutes).
HTH,
Scott
http://www.OdeToCode.com
On Sat, 4 Sep 2004 11:14:52 -0700, "Amith Singh"
<AmithSin@.hotmail.com> wrote:

>When the sessions times out I would like to take the user to the login page
.
>Currently even though session times out user will come to know only when he
>clicks on the screen. How to direct the user automatically to login page
>once the session times out. I am using .Net Framework 1.1. and IIS 5
>Amith
>
Amith Singh wrote:

> When the sessions times out I would like to take the user to the login pag
e.
> Currently even though session times out user will come to know only when h
e
> clicks on the screen. How to direct the user automatically to login page
> once the session times out. I am using .Net Framework 1.1. and IIS 5
> Amith
>
Run a cli9ent sided time somwhere somehow and when I reaches the 20
minutes (default session timeout setting) you do something like a popup,
redirect, etc.
//Rutger
DoDotNet@.Gmail.com
www.RutgerSmit.com
Rutger Smit wrote:

> Amith Singh wrote:
>
> Run a cli9ent sided time somwhere somehow and when I reaches the 20
> minutes (default session timeout setting) you do something like a popup,
> redirect, etc.
>
Where was my mind?
Here the intended answer:
Run a clientsided script somewhere somehow and when it reaches the 20
minutes (default session timeout setting) you do something like a popup,
redirect, etc.
//Rutger
DoDotNet@.Gmail.com
www.RutgerSmit.com
I tried doing something like this before. I added some client side code on
page load to redirect after 20 minutes or whatever. Problem was a user
could stay on the same page for more than 20 minutes and keep the session
alive by posting back to itself. But when the client side script hit 20
minutes from the initial page load... whoops... times up.
I would like to see a solution myself.
Greg
"Rutger Smit" <DoDotNet@.gmail.com> wrote in message
news:10jk7k75fscpdbb@.corp.supernews.com...
> Rutger Smit wrote:
>
> Where was my mind?
> Here the intended answer:
>
> Run a clientsided script somewhere somehow and when it reaches the 20
> minutes (default session timeout setting) you do something like a popup,
> redirect, etc.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com
Greg Burns wrote:

> I tried doing something like this before. I added some client side code o
n
> page load to redirect after 20 minutes or whatever. Problem was a user
> could stay on the same page for more than 20 minutes and keep the session
> alive by posting back to itself. But when the client side script hit 20
> minutes from the initial page load... whoops... times up.
> I would like to see a solution myself.
> Greg
>
>
>
Maybe you can make the script a little bit more intelligent.
On the client: do the time thing that redirects after 20 minutes.
Redirect the client to a special page that check wheter the session is
still alive or not. If it is, no broblem, redirect the client to the
HTTP_REFERER header value. If the session has expired, redir to login page.
//Rutger
DoDotNet@.Gmail.com
www.RutgerSmit.com
I would think if I redirected using HTTP_REFERER header value that it would
cause IsPostBack to False again, plus viewstate would not be retained. I
would be as if it was the first time visiting the page.
Here is some code I was playing with that I found while visiting the online
ticket ordering at sixflags.com.
function WarnUserTimeout()
{
alert('Your session has expired. You are being redirected to the park
selection page.')
window.location.href = "tickets_parkselect.asp";
}
<body OnLoad="window. setTimeout('WarnUserTimeout()',10*60*100
0)">
What would be great is if there was someway to reset the timer on every post
back...
Greg

> Maybe you can make the script a little bit more intelligent.
> On the client: do the time thing that redirects after 20 minutes.
> Redirect the client to a special page that check wheter the session is
> still alive or not. If it is, no broblem, redirect the client to the
> HTTP_REFERER header value. If the session has expired, redir to login
page.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com
Greg Burns wrote:
> I would think if I redirected using HTTP_REFERER header value that it woul
d
> cause IsPostBack to False again, plus viewstate would not be retained. I
> would be as if it was the first time visiting the page.
> Here is some code I was playing with that I found while visiting the onlin
e
> ticket ordering at sixflags.com.
> function WarnUserTimeout()
> {
> alert('Your session has expired. You are being redirected to the park
> selection page.')
> window.location.href = "tickets_parkselect.asp";
> }
> <body OnLoad="window. setTimeout('WarnUserTimeout()',10*60*100
0)">
> What would be great is if there was someway to reset the timer on every po
st
> back...
> Greg
>
>
'reset the timer on every post back'
It does since it's JavaScript and thus running client sided.
If you're using frames you have to do some cross frame scripting with a
function that sets the timer to zero.
//Rutger
DoDotNet@.Gmail.com
www.RutgerSmit.com
You know, you're right.
I just retested it to make sure I wasn't making this up, but couldn't
duplicate it. I definately had a problem with this very issue when I first
attempted this. I will need to take a second look.
Thanks,
Greg

> 'reset the timer on every post back'
> It does since it's JavaScript and thus running client sided.
> If you're using frames you have to do some cross frame scripting with a
> function that sets the timer to zero.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com

Session Times Out.... Navigate to Login Page

When the sessions times out I would like to take the user to the login page.
Currently even though session times out user will come to know only when he
clicks on the screen. How to direct the user automatically to login page
once the session times out. I am using .Net Framework 1.1. and IIS 5
AmithYou could force the browser to refresh after a set amount of time:

Response.AppendHeader("Refresh", (Session.Timeout * 60 +
10).ToString() + "; URL=Login.aspx");

This will calculate the time to refresh using the Session timeout
value on the server (specified in minutes).

HTH,

--
Scott
http://www.OdeToCode.com

On Sat, 4 Sep 2004 11:14:52 -0700, "Amith Singh"
<AmithSin@.hotmail.com> wrote:

>When the sessions times out I would like to take the user to the login page.
>Currently even though session times out user will come to know only when he
>clicks on the screen. How to direct the user automatically to login page
>once the session times out. I am using .Net Framework 1.1. and IIS 5
>Amith
Amith Singh wrote:

> When the sessions times out I would like to take the user to the login page.
> Currently even though session times out user will come to know only when he
> clicks on the screen. How to direct the user automatically to login page
> once the session times out. I am using .Net Framework 1.1. and IIS 5
> Amith

Run a cli9ent sided time somwhere somehow and when I reaches the 20
minutes (default session timeout setting) you do something like a popup,
redirect, etc.

--

//Rutger

DoDotNet@.Gmail.com
www.RutgerSmit.com
Rutger Smit wrote:

> Amith Singh wrote:
>
> Run a cli9ent sided time somwhere somehow and when I reaches the 20
> minutes (default session timeout setting) you do something like a popup,
> redirect, etc.

Where was my mind?
Here the intended answer:

Run a clientsided script somewhere somehow and when it reaches the 20
minutes (default session timeout setting) you do something like a popup,
redirect, etc.

--

//Rutger

DoDotNet@.Gmail.com
www.RutgerSmit.com
I tried doing something like this before. I added some client side code on
page load to redirect after 20 minutes or whatever. Problem was a user
could stay on the same page for more than 20 minutes and keep the session
alive by posting back to itself. But when the client side script hit 20
minutes from the initial page load... whoops... times up.

I would like to see a solution myself.

Greg

"Rutger Smit" <DoDotNet@.gmail.com> wrote in message
news:10jk7k75fscpdbb@.corp.supernews.com...
> Rutger Smit wrote:
> > Amith Singh wrote:
> > Run a cli9ent sided time somwhere somehow and when I reaches the 20
> > minutes (default session timeout setting) you do something like a popup,
> > redirect, etc.
> Where was my mind?
> Here the intended answer:
>
> Run a clientsided script somewhere somehow and when it reaches the 20
> minutes (default session timeout setting) you do something like a popup,
> redirect, etc.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com
Greg Burns wrote:

> I tried doing something like this before. I added some client side code on
> page load to redirect after 20 minutes or whatever. Problem was a user
> could stay on the same page for more than 20 minutes and keep the session
> alive by posting back to itself. But when the client side script hit 20
> minutes from the initial page load... whoops... times up.
> I would like to see a solution myself.
> Greg
>>Where was my mind?
>>Here the intended answer:
>>
>>
>>Run a clientsided script somewhere somehow and when it reaches the 20
>>minutes (default session timeout setting) you do something like a popup,
>> redirect, etc.
>>
>>--
>>
>>//Rutger
>>
>>DoDotNet@.Gmail.com
>>www.RutgerSmit.com

Maybe you can make the script a little bit more intelligent.
On the client: do the time thing that redirects after 20 minutes.
Redirect the client to a special page that check wheter the session is
still alive or not. If it is, no broblem, redirect the client to the
HTTP_REFERER header value. If the session has expired, redir to login page.

--

//Rutger

DoDotNet@.Gmail.com
www.RutgerSmit.com
I would think if I redirected using HTTP_REFERER header value that it would
cause IsPostBack to False again, plus viewstate would not be retained. I
would be as if it was the first time visiting the page.

Here is some code I was playing with that I found while visiting the online
ticket ordering at sixflags.com.

function WarnUserTimeout()
{
alert('Your session has expired. You are being redirected to the park
selection page.')
window.location.href = "tickets_parkselect.asp";
}

<body OnLoad="window.setTimeout('WarnUserTimeout()',10*60*1000)"
What would be great is if there was someway to reset the timer on every post
back...

Greg

> Maybe you can make the script a little bit more intelligent.
> On the client: do the time thing that redirects after 20 minutes.
> Redirect the client to a special page that check wheter the session is
> still alive or not. If it is, no broblem, redirect the client to the
> HTTP_REFERER header value. If the session has expired, redir to login
page.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com
Greg Burns wrote:
> I would think if I redirected using HTTP_REFERER header value that it would
> cause IsPostBack to False again, plus viewstate would not be retained. I
> would be as if it was the first time visiting the page.
> Here is some code I was playing with that I found while visiting the online
> ticket ordering at sixflags.com.
> function WarnUserTimeout()
> {
> alert('Your session has expired. You are being redirected to the park
> selection page.')
> window.location.href = "tickets_parkselect.asp";
> }
> <body OnLoad="window.setTimeout('WarnUserTimeout()',10*60*1000)">
> What would be great is if there was someway to reset the timer on every post
> back...
> Greg

'reset the timer on every post back'
It does since it's JavaScript and thus running client sided.
If you're using frames you have to do some cross frame scripting with a
function that sets the timer to zero.

--

//Rutger

DoDotNet@.Gmail.com
www.RutgerSmit.com
You know, you're right.

I just retested it to make sure I wasn't making this up, but couldn't
duplicate it. I definately had a problem with this very issue when I first
attempted this. I will need to take a second look.

Thanks,
Greg

> 'reset the timer on every post back'
> It does since it's JavaScript and thus running client sided.
> If you're using frames you have to do some cross frame scripting with a
> function that sets the timer to zero.
> --
> //Rutger
> DoDotNet@.Gmail.com
> www.RutgerSmit.com

Thursday, March 29, 2012

session value lost

Hello NG,

I have three files (default.aspx, search.aspx and work.aspx). The way
is: login on default (if session is newsession). The loginname I write
into as sessionvariable (username). So I redirect to my search.aspx.
Here I have a form which allows fill in some fields (place, street,
name etc.). With this informations i build a sqlquerey for sqlserver,
fill a datagrid and after select the right record by usin a link behind
I save the recordid to the session and redirect to work.aspx. With a
new sqlstring I fetch the data from the sqlserver. But this data is
only to display. The user can edit Data for a new record in anoter
table and end it wiht button click. Here I will save all sessionvalues
(username, and recordinformation) with sqlstring and redirect to
search.aspx.

Now the problems:
1. I don't no what I've changed - but I have to...
After redirection from work to search I've got an sql-error. The string
will be cleard before building new, so why does it run once, but not
after redirect?
2. I solved this problem with redirecting from work to default. Its
running. But: the session username is empty - why?
3. I solved with writing the username in an hidden field on
default.aspx, read it again and write to session. Everything is fine.
4. Now we can work, and I will change the username from manuel login to
reading from client windows. But I realy want to know why I have the
Problems 1 to 3 and problem no 4 is: some stored records have no
username within. Who can explain it to me - who as a solution to solve
the problems?You might want to share the source code for your search.aspx page so
we can look it over.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 27 Jun 2005 07:46:30 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hello NG,
>I have three files (default.aspx, search.aspx and work.aspx). The way
>is: login on default (if session is newsession). The loginname I write
>into as sessionvariable (username). So I redirect to my search.aspx.
>Here I have a form which allows fill in some fields (place, street,
>name etc.). With this informations i build a sqlquerey for sqlserver,
>fill a datagrid and after select the right record by usin a link behind
>I save the recordid to the session and redirect to work.aspx. With a
>new sqlstring I fetch the data from the sqlserver. But this data is
>only to display. The user can edit Data for a new record in anoter
>table and end it wiht button click. Here I will save all sessionvalues
>(username, and recordinformation) with sqlstring and redirect to
>search.aspx.
>Now the problems:
>1. I don't no what I've changed - but I have to...
>After redirection from work to search I've got an sql-error. The string
>will be cleard before building new, so why does it run once, but not
>after redirect?
>2. I solved this problem with redirecting from work to default. Its
>running. But: the session username is empty - why?
>3. I solved with writing the username in an hidden field on
>default.aspx, read it again and write to session. Everything is fine.
>4. Now we can work, and I will change the username from manuel login to
>reading from client windows. But I realy want to know why I have the
>Problems 1 to 3 and problem no 4 is: some stored records have no
>username within. Who can explain it to me - who as a solution to solve
>the problems?
Hi Allen,

it will be to much code but I think, it's better for understanding:

I start with the default.aspx. If the session is new, nothing will
happen unless the user logs in - no problem. When I come from my last
page (call.aspx) the sessionvariable 'user' has still a value. When I
redirect to my second page (suche.aspx) this value will be lost. So I
do this workaround:

default.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""

If Session.IsNewSession Then
TextBox1.value="neu"
else
if ispostback then
Session("Anwendername") = TextBoxLogin.value
TextBox1.value=Session("Anwendername")
response.redirect("suche.aspx")
else
TextBox1.value=Session("Anwendername")
Session("Anwendername") = TextBox1.value
response.redirect("suche.aspx")
end if
end if

When loading the suche.aspx I check on newsession and if not I will
clear the value of some session varialbes:

suche.aspx

Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)

If Session.IsNewSession Then
response.redirect("default.aspx")
else
dataSet
end if
end sub

public sub DataSet()
Session("KD_VNAME")=""
Session("KD_NAME")=""
Session("STADT")=""
Session("PLZ")=""
Session("STRASSE")=""
Datagrid1.DataBind()
end sub

After the user filled in the search date the function will be called.
First I had a redirect form my last page (call.aspx) back to this one.
If I am first on the page everything is fine. The second time, after
redirect I get an error, which means the sql statement is incorrect.
But there can no old value - I clear it. So I redirect to the
default.aspx:

function DatenSuche() As System.Data.IDataReader
Dim connectionString As String = "Data Source=mssql;Initial
Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
Library=dbmssocn;"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = ""
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand

if TextBox_Name.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
& "%' "
end if
if TextBox_Vorname.text <> "" then
if queryString <> "" then
queryString = querystring & " and "
end if
queryString = queryString & "[KD_VNAME] like N'" &
TextBox_Vorname.text & "%' "
end if

queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
queryString & ")"
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Return dataReader
dataReader.close
dbConnection.close
connectionString = ""
queryString = ""
end function

call.aspx

public sub ButtonEnde_Click(sender As Object, e As EventArgs)
response.redirect("default.aspx")
'response.redirect("suche.aspx")
end sub

Any idea?
One thing you may want to try is to use:

Response.Redirect("page", False);

Whenever you are in a page where the user might have started a
session. See:
http://weblogs.asp.net/bleroy/archi.../03/207486.aspx

Another approach I'd try is to not use so many redirects, but drop a
panel control on your form and keep the search results inside the
panel. You can set the Visible property of the panel to false, and
toggle the value to true when there are search results to display.
This might make the page easier to work with.

--
Scott
http://www.OdeToCode.com/blogs/scott/]

On 29 Jun 2005 04:04:53 -0700, "catweezle2010" <catweezle2010@.gmx.de>
wrote:

>Hi Allen,
>it will be to much code but I think, it's better for understanding:
>I start with the default.aspx. If the session is new, nothing will
>happen unless the user logs in - no problem. When I come from my last
>page (call.aspx) the sessionvariable 'user' has still a value. When I
>redirect to my second page (suche.aspx) this value will be lost. So I
>do this workaround:
>default.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
> Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
>If Session.IsNewSession Then
> TextBox1.value="neu"
> else
> if ispostback then
> Session("Anwendername") = TextBoxLogin.value
> TextBox1.value=Session("Anwendername")
> response.redirect("suche.aspx")
> else
> TextBox1.value=Session("Anwendername")
> Session("Anwendername") = TextBox1.value
> response.redirect("suche.aspx")
> end if
> end if
>When loading the suche.aspx I check on newsession and if not I will
>clear the value of some session varialbes:
>suche.aspx
>Sub Page_Load (ByVal Sender As Object, _
> ByVal E As EventArgs)
>If Session.IsNewSession Then
> response.redirect("default.aspx")
> else
> dataSet
> end if
>end sub
>public sub DataSet()
>Session("KD_VNAME")=""
> Session("KD_NAME")=""
> Session("STADT")=""
> Session("PLZ")=""
> Session("STRASSE")=""
> Datagrid1.DataBind()
>end sub
>
>After the user filled in the search date the function will be called.
>First I had a redirect form my last page (call.aspx) back to this one.
>If I am first on the page everything is fine. The second time, after
>redirect I get an error, which means the sql statement is incorrect.
>But there can no old value - I clear it. So I redirect to the
>default.aspx:
>function DatenSuche() As System.Data.IDataReader
> Dim connectionString As String = "Data Source=mssql;Initial
>Catalog=DB;User Id=huser;Password=passw;Connect Timeout=15;Network
>Library=dbmssocn;"
> Dim dbConnection As System.Data.IDbConnection = New
>System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = ""
> Dim dbCommand As System.Data.IDbCommand = New
>System.Data.SqlClient.SqlCommand
> if TextBox_Name.text <> "" then
>if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_NAME] like N'" & TextBox_Name.text
>& "%' "
> end if
> if TextBox_Vorname.text <> "" then
> if queryString <> "" then
> queryString = querystring & " and "
> end if
> queryString = queryString & "[KD_VNAME] like N'" &
>TextBox_Vorname.text & "%' "
> end if
>
> queryString = "SELECT [View_Such].* FROM [View_Such] WHERE (" &
>queryString & ")"
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> dbConnection.Open
> Dim dataReader As System.Data.IDataReader =
>dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
> Return dataReader
> dataReader.close
> dbConnection.close
> connectionString = ""
> queryString = ""
>end function
>
>call.aspx
>public sub ButtonEnde_Click(sender As Object, e As EventArgs)
> response.redirect("default.aspx")
> 'response.redirect("suche.aspx")
> end sub
>
>
>Any idea?

Session Var

Ok, i made a gaming clan website. It has a login that uses session vars to store the username and pwd. I am experiencing an issue of logging out.

Does the time out mean time from creation?, like 20 min after the var is created, it kills it.

How do i keep the session var open while the person is on the site.session variables are active for the time that a person is on the site and is actively viewing (interacting with the server) the site.

If a person does not send any information back to the server within 20 minutes then their session variable expires. If they interact with the server (clicking on a link, posting a form etc) then their session variable is kept alive until the time they explicitly logout (Click on a logout button), close the browser or do not interact with the server for the default session timeout time..

hth
Cheers
MarkusJ
thats what i have heard but... it like isn't true for my case for some reason, cause i could be surfing around logged in and i will get logged out all of the sudden. I also have a page that refreshes its self every 5 min on a very small frame on the left bar...
Are you using frames/ pop up windows?
i have 2 main frames, a leftbar and a main window. Then i have the refreshing frame in the leftbar frame.
AFAIK there are some issues with frames and session variables

A quick search of the newsgroups reflects this

http://tinyurl.com/ifiw

Cheers
MarkusJ
that is only for ie below 5.5

and i don't really lose them between frames, they just die after 20 min, even if the person is active.
You should be using a different way to authenticate users like form. Holding the log in values in session variables isn't the way to do it. MS provided a couple different authentication methods, and they are full featured and quite good at what they do. You can use Windows, Forms, Passport or None (which is what you are doing). You should be using Forms authentication if you want to handle the authentication through code. Lethal posted some good authentication code at this link:
http://www.vbforums.com/showthread.php?s=&threadid=245643
Indeed,

like hellswraith said you ... There are other sorts of authentication. Session variables are very good to keep data in memory for a short time.
Use an authentication ticket

Dim objTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, Username, DateTime.Now, DateTime.Now.AddMinutes(60), False, String.Join("|", varRole))

1,
Username,
DateTime.Now,
DateTime.Now.AddMinutes(60), <<< EXPIRE DATE
False,
String.Join("|", varRole))

u can find full code for using the ticket in post http://www.vbforums.com/showthread.php?s=&threadid=257238

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

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?
>

Monday, March 26, 2012

Session variable got lost after I switched to another server

The scenario is the following: from the login page I set a session variable
like
Session["USERID"]=3;
Server.transfer("anotherpage.aspx");
In anotherpage.aspx in page load I check to see if that Session is null, if
it's not show a javascript message window with the ID. The funny thing is
that the window is open, ->the variable gets to this page. Good, untill now!
If I click a button from this anotherpage.aspx to
Server.transfer(clients.aspx) and in clients.aspx I try to acces the
Session["USERID"] it says that it is gone (I mean if I cast to string type,
the resulting value is null).
Now the boom (for me) At work (Win 2000) this used to work, however when I
transfered at my house (WinXP Pro SP 1 with all updates) it doesn't!!!!
What happens to that variable'Can you write out the value of your session id to make sure it is not
changing between postbacks?
"Vlady" wrote:

> The scenario is the following: from the login page I set a session variabl
e
> like
> Session["USERID"]=3;
> Server.transfer("anotherpage.aspx");
> In anotherpage.aspx in page load I check to see if that Session is null, i
f
> it's not show a javascript message window with the ID. The funny thing is
> that the window is open, ->the variable gets to this page. Good, untill no
w!
> If I click a button from this anotherpage.aspx to
> Server.transfer(clients.aspx) and in clients.aspx I try to acces the
> Session["USERID"] it says that it is gone (I mean if I cast to string type
,
> the resulting value is null).
> Now the boom (for me) At work (Win 2000) this used to work, however when I
> transfered at my house (WinXP Pro SP 1 with all updates) it doesn't!!!!
> What happens to that variable'

Session variable got lost after I switched to another server

The scenario is the following: from the login page I set a session variable
like
Session["USERID"]=3;
Server.transfer("anotherpage.aspx");
In anotherpage.aspx in page load I check to see if that Session is null, if
it's not show a javascript message window with the ID. The funny thing is
that the window is open, ->the variable gets to this page. Good, untill now!
If I click a button from this anotherpage.aspx to
Server.transfer(clients.aspx) and in clients.aspx I try to acces the
Session["USERID"] it says that it is gone (I mean if I cast to string type,
the resulting value is null).
Now the boom (for me) At work (Win 2000) this used to work, however when I
transfered at my house (WinXP Pro SP 1 with all updates) it doesn't!!!!
What happens to that variable??Can you write out the value of your session id to make sure it is not
changing between postbacks?

"Vlady" wrote:

> The scenario is the following: from the login page I set a session variable
> like
> Session["USERID"]=3;
> Server.transfer("anotherpage.aspx");
> In anotherpage.aspx in page load I check to see if that Session is null, if
> it's not show a javascript message window with the ID. The funny thing is
> that the window is open, ->the variable gets to this page. Good, untill now!
> If I click a button from this anotherpage.aspx to
> Server.transfer(clients.aspx) and in clients.aspx I try to acces the
> Session["USERID"] it says that it is gone (I mean if I cast to string type,
> the resulting value is null).
> Now the boom (for me) At work (Win 2000) this used to work, however when I
> transfered at my house (WinXP Pro SP 1 with all updates) it doesn't!!!!
> What happens to that variable??

Session Variable Madness

Here's one that has been stumping people:

I'm writing in ASPX with VB.NET

On the login page I set the entered usename text to a session
variable.
************************************************** **********************
Private Sub lbtnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbtnSubmit.Click
Dim bolLogin As Boolean

If Page.IsValid Then
Session("ctc_username") = txtUsername.Text.ToUpper()
Response.Redirect("acchist.aspx")
End If
End Sub
************************************************** ***********************
On the next/called page "acchist.aspx" I assign the session variable
to the text of lblUser.
************************************************** ***********************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Page.IsPostBack Then

Else
lblUser.Text = Session("ctc_username")
End If
End Sub
************************************************** ***********************
Here's where the strange behavior starts. In IE6 the session variable
will display in lblUser on the page load. However, if the page is
refreshed the session variable disappears from both lblUser and the
page trace. If the page is repeatedly refreshed the session variable
will begin to alternate as there or not. In Netscape 7.0 the first
time that the called page loads the session variable doesn't appear
and then begins with the smae behavior on repeated refresh.

You can check it out at the following address:
www5dev.nau.edu/ctc/registration/login.aspx
Put in any username and password.

Does anyone know what is causing this and/or how to get the session
variable to remain consistent?

Thanks,
Todd Bohlander
Ancillary Systems Development
Information Technology Services
Northern Arizona UniversityTodd,

typically a refresh means that you are no longer in the same session, and so
results in the cache being flushed. why it's reappearing after than I'm not
sure.

Why not assign the name to a text box or a label that has the
EnableViewState enabled (default) and set them visible=false if you don't
want to see them. This should provide more consistency in this case.

hope this helps.
Dan.

"Todd" <rtb22@.dana.ucc.nau.edu> wrote in message
news:e7dd1133.0401210844.65048300@.posting.google.c om...
Here's one that has been stumping people:

I'm writing in ASPX with VB.NET

On the login page I set the entered usename text to a session
variable.
************************************************** **********************
Private Sub lbtnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbtnSubmit.Click
Dim bolLogin As Boolean

If Page.IsValid Then
Session("ctc_username") = txtUsername.Text.ToUpper()
Response.Redirect("acchist.aspx")
End If
End Sub
************************************************** ***********************
On the next/called page "acchist.aspx" I assign the session variable
to the text of lblUser.
************************************************** ***********************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Page.IsPostBack Then

Else
lblUser.Text = Session("ctc_username")
End If
End Sub
************************************************** ***********************
Here's where the strange behavior starts. In IE6 the session variable
will display in lblUser on the page load. However, if the page is
refreshed the session variable disappears from both lblUser and the
page trace. If the page is repeatedly refreshed the session variable
will begin to alternate as there or not. In Netscape 7.0 the first
time that the called page loads the session variable doesn't appear
and then begins with the smae behavior on repeated refresh.

You can check it out at the following address:
www5dev.nau.edu/ctc/registration/login.aspx
Put in any username and password.

Does anyone know what is causing this and/or how to get the session
variable to remain consistent?

Thanks,
Todd Bohlander
Ancillary Systems Development
Information Technology Services
Northern Arizona University
Are you using web farm or web gardening? If so what type of session state
are you using?

"Todd" <rtb22@.dana.ucc.nau.edu> wrote in message
news:e7dd1133.0401210844.65048300@.posting.google.c om...
> Here's one that has been stumping people:
> I'm writing in ASPX with VB.NET
> On the login page I set the entered usename text to a session
> variable.
> ************************************************** **********************
> Private Sub lbtnSubmit_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles lbtnSubmit.Click
> Dim bolLogin As Boolean
> If Page.IsValid Then
> Session("ctc_username") = txtUsername.Text.ToUpper()
> Response.Redirect("acchist.aspx")
> End If
> End Sub
> ************************************************** ***********************
> On the next/called page "acchist.aspx" I assign the session variable
> to the text of lblUser.
> ************************************************** ***********************
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Page.IsPostBack Then
> Else
> lblUser.Text = Session("ctc_username")
> End If
> End Sub
> ************************************************** ***********************
> Here's where the strange behavior starts. In IE6 the session variable
> will display in lblUser on the page load. However, if the page is
> refreshed the session variable disappears from both lblUser and the
> page trace. If the page is repeatedly refreshed the session variable
> will begin to alternate as there or not. In Netscape 7.0 the first
> time that the called page loads the session variable doesn't appear
> and then begins with the smae behavior on repeated refresh.
> You can check it out at the following address:
> www5dev.nau.edu/ctc/registration/login.aspx
> Put in any username and password.
> Does anyone know what is causing this and/or how to get the session
> variable to remain consistent?
> Thanks,
> Todd Bohlander
> Ancillary Systems Development
> Information Technology Services
> Northern Arizona University

Session variable not set

Hi All,
I built a web application using cookieless session. It merely checks
for the session variable value upon login. This method works fine on
the host pc.
However, when i try to access the application via another pc in the
network, the login page redirects to itself even though the correct
passwd and usename is entered. I did a response.write and realise that
the value of the session variable is not set. How can i solve this
prob?
Any Help is greatly appreciated.
Tks...ywzCheck out http://weblogs.asp.net/bleroy/archi.../03/207486.aspx
it might solve your problem...
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!)
"ywz" <ywz.oct13@.gmail.com> wrote in message
news:1113293239.075593.241860@.o13g2000cwo.googlegroups.com...
> Hi All,
>
> I built a web application using cookieless session. It merely checks
> for the session variable value upon login. This method works fine on
> the host pc.
> However, when i try to access the application via another pc in the
> network, the login page redirects to itself even though the correct
> passwd and usename is entered. I did a response.write and realise that
> the value of the session variable is not set. How can i solve this
> prob?
>
> Any Help is greatly appreciated.
> Tks...ywz
>
The fact that it works on one and not the other means this is probably not
the answer, although this is a great post.
The major problem, IMO, is the fact that ywz is using an ASP methodology
(session var) in an ASP.NET world.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Karl Seguin" wrote:

> Check out http://weblogs.asp.net/bleroy/archi.../03/207486.aspx
> it might solve your problem...
> 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!)
>
> "ywz" <ywz.oct13@.gmail.com> wrote in message
> news:1113293239.075593.241860@.o13g2000cwo.googlegroups.com...
>
>

Session variable not set

Hi All,

I built a web application using cookieless session. It merely checks
for the session variable value upon login. This method works fine on
the host pc.
However, when i try to access the application via another pc in the
network, the login page redirects to itself even though the correct
passwd and usename is entered. I did a response.write and realise that
the value of the session variable is not set. How can i solve this
prob?

Any Help is greatly appreciated.
Tks...ywzCheck out http://weblogs.asp.net/bleroy/archi.../03/207486.aspx
it might solve your problem...

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!)

"ywz" <ywz.oct13@.gmail.com> wrote in message
news:1113293239.075593.241860@.o13g2000cwo.googlegr oups.com...
> Hi All,
>
> I built a web application using cookieless session. It merely checks
> for the session variable value upon login. This method works fine on
> the host pc.
> However, when i try to access the application via another pc in the
> network, the login page redirects to itself even though the correct
> passwd and usename is entered. I did a response.write and realise that
> the value of the session variable is not set. How can i solve this
> prob?
>
> Any Help is greatly appreciated.
> Tks...ywz
The fact that it works on one and not the other means this is probably not
the answer, although this is a great post.

The major problem, IMO, is the fact that ywz is using an ASP methodology
(session var) in an ASP.NET world.

--

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

***************************
Think Outside the Box!
***************************

"Karl Seguin" wrote:

> Check out http://weblogs.asp.net/bleroy/archi.../03/207486.aspx
> it might solve your problem...
> 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!)
>
> "ywz" <ywz.oct13@.gmail.com> wrote in message
> news:1113293239.075593.241860@.o13g2000cwo.googlegr oups.com...
> > Hi All,
> > I built a web application using cookieless session. It merely checks
> > for the session variable value upon login. This method works fine on
> > the host pc.
> > However, when i try to access the application via another pc in the
> > network, the login page redirects to itself even though the correct
> > passwd and usename is entered. I did a response.write and realise that
> > the value of the session variable is not set. How can i solve this
> > prob?
> > Any Help is greatly appreciated.
> > Tks...ywz
>

Session variable problem

Hi,
Please help me with the following:
In login.aspx page:
Session("accessGranted") = 1
Response.Write("<script>window.open(""userpage.aspx"", ""User"");</script>")
In userpage.aspx:
<body>
<script language="vb" runat="server">
Sub Page_Load(source as Object, e as EventArgs)
if Session("accessGranted") is nothing then
response.redirect("login_failed.htm")
end if
end sub
</script>
Problem:
Every time a user logs in the first time the userpage.aspx doesn't see the S
ession and kicks the user out. However, when you repeat the login, the page
sees the Session. It looks as if the session were created then the userpage
opens - can it be? What s
hould I do to avoid this problem?
Thanks,
Alex Fimine
alex@dotnet.itags.org.agfconsulting.com> It looks as if the session were created then the userpage opens
According to your code, the Session variable is initialized BEFORE userpage
opens:

> In login.aspx page:
> Session("accessGranted") = 1
> Response.Write("<script>window.open(""userpage.aspx"",
""User"");</script>")
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Alex Fimine" <AlexFimine@.discussions.microsoft.com> wrote in message
news:926DE728-127C-47D5-ADBD-F517C726D2A2@.microsoft.com...
> Hi,
> Please help me with the following:
> In login.aspx page:
> Session("accessGranted") = 1
> Response.Write("<script>window.open(""userpage.aspx"",
""User"");</script>")
>
> In userpage.aspx:
> <body>
> <script language="vb" runat="server">
> Sub Page_Load(source as Object, e as EventArgs)
> if Session("accessGranted") is nothing then
> response.redirect("login_failed.htm")
> end if
> end sub
> </script>
> Problem:
> Every time a user logs in the first time the userpage.aspx doesn't see the
Session and kicks the user out. However, when you repeat the login, the page
sees the Session. It looks as if the session were created then the userpage
opens - can it be? What should I do to avoid this problem?
>
> Thanks,
> Alex Fimine
> alex@.agfconsulting.com
Kevin, I know that according to the code the session is created BEFORE - tha
t, not surprisingly, was my intention. However, as I explained, there is a p
roblem with that.
"Kevin Spencer" wrote:

> According to your code, the Session variable is initialized BEFORE userpag
e
> opens:
>
> ""User"");</script>")
> --
> HTH,
> Kevin Spencer
> ..Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Alex Fimine" <AlexFimine@.discussions.microsoft.com> wrote in message
> news:926DE728-127C-47D5-ADBD-F517C726D2A2@.microsoft.com...
> ""User"");</script>")
> Session and kicks the user out. However, when you repeat the login, the pa
ge
> sees the Session. It looks as if the session were created then the userpa
ge
> opens - can it be? What should I do to avoid this problem?
>
>

Saturday, March 24, 2012

Session variable problem

Hi,

Please help me with the following:

In login.aspx page:

Session("accessGranted") = 1
Response.Write("<script>window.open(""userpage.aspx"", ""User"");</script>")

In userpage.aspx:

<body>
<script language="vb" runat="server"
Sub Page_Load(source as Object, e as EventArgs)

if Session("accessGranted") is nothing then
response.redirect("login_failed.htm")
end if

end sub

</script
Problem:
Every time a user logs in the first time the userpage.aspx doesn't see the Session and kicks the user out. However, when you repeat the login, the page sees the Session. It looks as if the session were created then the userpage opens - can it be? What should I do to avoid this problem?

Thanks,

Alex Fimine
alex@dotnet.itags.org.agfconsulting.com> It looks as if the session were created then the userpage opens

According to your code, the Session variable is initialized BEFORE userpage
opens:

> In login.aspx page:
> Session("accessGranted") = 1
> Response.Write("<script>window.open(""userpage.aspx"",
""User"");</script>")

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Alex Fimine" <AlexFimine@.discussions.microsoft.com> wrote in message
news:926DE728-127C-47D5-ADBD-F517C726D2A2@.microsoft.com...
> Hi,
> Please help me with the following:
> In login.aspx page:
> Session("accessGranted") = 1
> Response.Write("<script>window.open(""userpage.aspx"",
""User"");</script>")
>
> In userpage.aspx:
> <body>
> <script language="vb" runat="server">
> Sub Page_Load(source as Object, e as EventArgs)
> if Session("accessGranted") is nothing then
> response.redirect("login_failed.htm")
> end if
> end sub
> </script>
> Problem:
> Every time a user logs in the first time the userpage.aspx doesn't see the
Session and kicks the user out. However, when you repeat the login, the page
sees the Session. It looks as if the session were created then the userpage
opens - can it be? What should I do to avoid this problem?
>
> Thanks,
> Alex Fimine
> alex@.agfconsulting.com
Kevin, I know that according to the code the session is created BEFORE - that, not surprisingly, was my intention. However, as I explained, there is a problem with that.

"Kevin Spencer" wrote:

> > It looks as if the session were created then the userpage opens
> According to your code, the Session variable is initialized BEFORE userpage
> opens:
> > In login.aspx page:
> > Session("accessGranted") = 1
> > Response.Write("<script>window.open(""userpage.aspx"",
> ""User"");</script>")
> --
> HTH,
> Kevin Spencer
> ..Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Alex Fimine" <AlexFimine@.discussions.microsoft.com> wrote in message
> news:926DE728-127C-47D5-ADBD-F517C726D2A2@.microsoft.com...
> > Hi,
> > Please help me with the following:
> > In login.aspx page:
> > Session("accessGranted") = 1
> > Response.Write("<script>window.open(""userpage.aspx"",
> ""User"");</script>")
> > In userpage.aspx:
> > <body>
> > <script language="vb" runat="server">
> > Sub Page_Load(source as Object, e as EventArgs)
> > if Session("accessGranted") is nothing then
> > response.redirect("login_failed.htm")
> > end if
> > end sub
> > </script>
> > Problem:
> > Every time a user logs in the first time the userpage.aspx doesn't see the
> Session and kicks the user out. However, when you repeat the login, the page
> sees the Session. It looks as if the session were created then the userpage
> opens - can it be? What should I do to avoid this problem?
> > Thanks,
> > Alex Fimine
> > alex@.agfconsulting.com
>

Session variable, need help!

Hi All!

In my login page, I created a session variable to hold the username(studentId). It's not working! It's very frustrating!! Anybody figure out what my problem is?!

My Code:

Login page Code:

Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then

dim user as string = UserName.Text
Session("StudentID") = user

End If
End Sub

Sub LoginBtn_Click(Sender As Object, E As EventArgs)

If Page.IsValid Then
Dim userDS As New System.Data.DataSet

userDS = password(UserName.Text, UserPass.Text)

If userDS.Tables(0).Rows.Count = 1 Then

FormsAuthentication.RedirectFromLoginPage(UserName.Text, true)
Else
Msg.Text = "***Invalid Credentials: Please try again***"
End If
End If

End Sub


Next Page Code:

Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then


Dim id = CType(Session("StudentID"), string)
Label1.Text = id.ToString()


End If
End Sub

make sure that you have session enabled.

Hi!

Don't know how to do that! Can you explain to me how I can do it?

Collette


I think the problem is that you are setting the session variable in thepage load method, and at that time UserName.Text is probablyblank! Try creating the session variable in the click event ofthe login button and see if that solves the problem.

Hi!

I tried this:

Sub LoginBtn_Click(Sender As Object, E As EventArgs)

If Page.IsValid Then
Dim userDS As New System.Data.DataSet

userDS = password(UserName.Text, UserPass.Text)

Session("UserName") = user

If userDS.Tables(0).Rows.Count = 1 Then

FormsAuthentication.RedirectFromLoginPage(UserName.Text, true)
Else
Msg.Text = "***Invalid Credentials: Please try again***"
End If
End If

End Sub

Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then

dim user as string
user = UserName.Text

End If
End Sub

But Im getting the following error:

Object reference not set to an instance of an object.

Please help!!!



Panic Over!!

Sussed it out, appreciate the help I got, Thanx guys!Wink [;)]


Your variable "User" is not a global variable in your page. It islocal to the Page_Load method and hence not usable in any other method.
Try the following ... note the change in the underlined text.

Sub LoginBtn_Click(Sender As Object, E As EventArgs)

If Page.IsValid Then
Dim userDS As New System.Data.DataSet

userDS = password(UserName.Text, UserPass.Text)

Session("UserName") = UserName.Text

If userDS.Tables(0).Rows.Count = 1 Then

FormsAuthentication.RedirectFromLoginPage(UserName.Text, true)
Else
Msg.Text = "***Invalid Credentials: Please try again***"
End If
End If

End Sub