468,505 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Hyperlinking and ASP.NEt Session

Hi,

I am trying to design a Home page for my applicatiion in which i want show
the links for for some itms...
I tried to put the following
<td>
<font face="Arial, Helvetica, sans-serif" color="#ffffff" size="2"> Contact
| My Profile | Logout /font>
</td>

Here i want to have link for the above options to respective pages, i tried
with anchor <A></A> with HREF attribute, but i don't want to see the
underline for the link., i am not sure of how to do that...would anyone help
me in this regard.

ASP.NET Session variables Questions?

1) How to discard session variables? Are all session variables cleared when
the code FormsAuthentication.SignOut() is executed for Forms authentication
web
applications (i am sessing this not happening, even after using
Session.Abandon(), Session.Clear())

2) Is session variables persistent across hyperliks (i think it is not,
since each hyperlink will assume diferent session)

3) How to check for user Session expiration to pop up a messgae saying
"Session Expired, goto Login page"

Thanks
Nedu

Nov 18 '05 #1
6 2328
See inline comments.
I am trying to design a Home page for my applicatiion in which i want show
the links for for some itms...
I tried to put the following
<td>
<font face="Arial, Helvetica, sans-serif" color="#ffffff" size="2"> Contact | My Profile | Logout /font>
</td>

Here i want to have link for the above options to respective pages, i tried with anchor <A></A> with HREF attribute, but i don't want to see the
underline for the link., i am not sure of how to do that...would anyone help me in this regard.
Use stylesheets for your links.

<style>
a.navlink
{
font-family: arial, helvetica, sans-serif;
font-size: 11px;
color: #ffffff;
text-decoration: none;
}
</style>

<a href="blah.aspx" class="navlink">Contact</a> ...etc

ASP.NET Session variables Questions?

1) How to discard session variables? Are all session variables cleared when the code FormsAuthentication.SignOut() is executed for Forms authentication web applications (i am sessing this not happening, even after using
Session.Abandon(), Session.Clear())
FormsAuthentication.SignOut() will clear the session variables set by the
ASP.NET authentication system. However, if you hit back on your browser,
the page will be pulled from your browser cache, and will display. Hitting
refresh on this page will cause it to re-request the page from the server,
at which point it will realise you are no longer logged in, and will
redirect to the login page, as defined in web.config.

2) Is session variables persistent across hyperliks (i think it is not,
since each hyperlink will assume diferent session)
Session variables are persistent across a users session, across hyperlinks
within the same domain and IIS application.

3) How to check for user Session expiration to pop up a messgae saying
"Session Expired, goto Login page"


You will need to do this using Javascript and timers. Create a timer on
each page load, in which you pass in the session timeout. When the timer
elapses, use the alert command to display a warning message.
Regards,

Mun

Nov 18 '05 #2
Thanks Mun.
I was trying to use Timer object for Session Timeout popup and redirect
already, but it was not not working...
would you give me exaple of how to code time controls to popup a message and
redirect to login page when the session times out..
(using Session.Timeout property to determine the session timout).

Thanks
Nedu

"Munsifali Rashid" <mun.news@#RemoveToReply#cordlessmouse.co.uk> wrote in
message news:eB**************@TK2MSFTNGP12.phx.gbl...
See inline comments.
I am trying to design a Home page for my applicatiion in which i want show the links for for some itms...
I tried to put the following
<td>
<font face="Arial, Helvetica, sans-serif" color="#ffffff" size="2"> Contact
| My Profile | Logout /font>
</td>

Here i want to have link for the above options to respective pages, i

tried
with anchor <A></A> with HREF attribute, but i don't want to see the
underline for the link., i am not sure of how to do that...would anyone

help
me in this regard.


Use stylesheets for your links.

<style>
a.navlink
{
font-family: arial, helvetica, sans-serif;
font-size: 11px;
color: #ffffff;
text-decoration: none;
}
</style>

<a href="blah.aspx" class="navlink">Contact</a> ...etc

ASP.NET Session variables Questions?

1) How to discard session variables? Are all session variables cleared

when
the code FormsAuthentication.SignOut() is executed for Forms

authentication
web applications (i am sessing this not happening, even after using
Session.Abandon(), Session.Clear())


FormsAuthentication.SignOut() will clear the session variables set by the
ASP.NET authentication system. However, if you hit back on your browser,
the page will be pulled from your browser cache, and will display.

Hitting refresh on this page will cause it to re-request the page from the server,
at which point it will realise you are no longer logged in, and will
redirect to the login page, as defined in web.config.

2) Is session variables persistent across hyperliks (i think it is not,
since each hyperlink will assume diferent session)


Session variables are persistent across a users session, across hyperlinks
within the same domain and IIS application.

3) How to check for user Session expiration to pop up a messgae saying
"Session Expired, goto Login page"


You will need to do this using Javascript and timers. Create a timer on
each page load, in which you pass in the session timeout. When the timer
elapses, use the alert command to display a warning message.
Regards,

Mun

Nov 18 '05 #3
Hi Nedu,

Instead of a timer object, you may use the setTimeout method, for example:

window.setTimeout(window.alert(""Session Expired, goto Login page!",100000)

For more information on this method, you can refer to:

http://msdn.microsoft.com/library/de...thor/dhtml/ref
erence/methods/setTimeout.asp

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
What you need to do, is start a javascript timer on each page load, and then
update the timer every second until the session expires. If the user
navigates to a different page, the clock will reset as they are actively
using the session.

Create a timers javascript file and put the following two functions in it.
This script must be referenced in every page on which you want to show the
popup. I.e. save it as "includes/timers.js" and then each page must
reference it using <script language="JavaScript"
src="includes/timers.js"></script>.
function startClock()
{
dWatch = 0;
dStarted = new Date();
}
function updateClock(iTimeOutAlert)
{
setTimeout("updateClock('" + iTimeOutAlert + "');", 100);
dNow = new Date();
dWatch = dNow.getTime() - dStarted.getTime();
dClock = Math.round(dWatch/1000);
if (dClock == iTimeOutAlert)
{
alert("Warning!\n\nYour session has expired.\nRedirecting to login
page...");
window.location.href = "loginpage.aspx";
}
}
Once this is done, you need to modify pages using the alert to call
startClock() and updateClock(). You can do this using the following (in the
Page_Load function):
[C#]
int intTimeOut = Session.Timeout*100;
string strTimerScript = "startClock();updateClock(" + intTimeOut.ToString()
+ ");"
Page.RegisterStartupScript("timerScript", strTimerScript);
[VB.NET]
Dim intTimeOut as Integer = Session.Timeout*100
Dim strTimerScript As String = "startClock();updateClock(" &
intTimeOut.ToString() & ");"
Page.RegisterStartupScript("timerScript", strTimerScript)
This code sample is constructed partly from memory, and partly from some
code snippets I had floating around. Haven't used it for a coupla years
now, though it worked perfectly back then, but it was being used on a
classic ASP website, not .NET. That shouldn't be an issue though, as it's
all client-side code. If there's any problems, let me know, and I'll try
and help :-)

Regards,

Mun

"Nedu N" <ne****@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP11.phx.gbl...
Thanks Mun.
I was trying to use Timer object for Session Timeout popup and redirect
already, but it was not not working...
would you give me exaple of how to code time controls to popup a message and redirect to login page when the session times out..
(using Session.Timeout property to determine the session timout).

Thanks
Nedu

Nov 18 '05 #5
Thanks Mun...
I tried but i am make it working...i just tried with the script that you
gave me..

I created a js file in my project itself - TimeoutTimer.js
and i referenced this on one of my page's HTML as reference it using <script
language="JavaScript"
src="TimeoutTimer.js"></script>.

and i had following code in my page load
Session.Timeout = 10; //i am ust overriding this...

int intTimeOut = Session.Timeout * 100;

Global.strScript = "startClock();updateClock(" + intTimeOut.ToString() + ");

Page.RegisterStartupScript("timerScript", Global.strScript);

But the output that i am getting is the following displayed on my page as a
string...i think the the javascript was not executed...woudl u please tell
me what is the problem since i am new to scripts..

startClock();updateClock(1000)

"Munsifali Rashid" <mun@**RemoveToReply**vefuk.com> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
What you need to do, is start a javascript timer on each page load, and then update the timer every second until the session expires. If the user
navigates to a different page, the clock will reset as they are actively
using the session.

Create a timers javascript file and put the following two functions in it.
This script must be referenced in every page on which you want to show the
popup. I.e. save it as "includes/timers.js" and then each page must
reference it using <script language="JavaScript"
src="includes/timers.js"></script>.
function startClock()
{
dWatch = 0;
dStarted = new Date();
}
function updateClock(iTimeOutAlert)
{
setTimeout("updateClock('" + iTimeOutAlert + "');", 100);
dNow = new Date();
dWatch = dNow.getTime() - dStarted.getTime();
dClock = Math.round(dWatch/1000);
if (dClock == iTimeOutAlert)
{
alert("Warning!\n\nYour session has expired.\nRedirecting to login
page...");
window.location.href = "loginpage.aspx";
}
}
Once this is done, you need to modify pages using the alert to call
startClock() and updateClock(). You can do this using the following (in the Page_Load function):
[C#]
int intTimeOut = Session.Timeout*100;
string strTimerScript = "startClock();updateClock(" + intTimeOut.ToString() + ");"
Page.RegisterStartupScript("timerScript", strTimerScript);
[VB.NET]
Dim intTimeOut as Integer = Session.Timeout*100
Dim strTimerScript As String = "startClock();updateClock(" &
intTimeOut.ToString() & ");"
Page.RegisterStartupScript("timerScript", strTimerScript)
This code sample is constructed partly from memory, and partly from some
code snippets I had floating around. Haven't used it for a coupla years
now, though it worked perfectly back then, but it was being used on a
classic ASP website, not .NET. That shouldn't be an issue though, as it's
all client-side code. If there's any problems, let me know, and I'll try
and help :-)

Regards,

Mun

"Nedu N" <ne****@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP11.phx.gbl...
Thanks Mun.
I was trying to use Timer object for Session Timeout popup and redirect
already, but it was not not working...
would you give me exaple of how to code time controls to popup a message

and
redirect to login page when the session times out..
(using Session.Timeout property to determine the session timout).

Thanks
Nedu


Nov 18 '05 #6
There's an error in the code - I forgot to wrap the javascript in <script>
tags.

Global.strScript = "startClock();updateClock(" + intTimeOut.ToString() + ");

Should be:

Global.strScript = "<script language='JavaScript'>startClock();updateClock("
+ intTimeOut.ToString() + ");</script>";

Also, the number passed in should be the Session.Timeout in seconds, so
intTimeOut should be:

int intTimeOut = Session.Timeout * 60;

I've just tested this code, and it seems to be working.

Hope this helps,

Mun

"Nedu N" <ne****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thanks Mun...
I tried but i am make it working...i just tried with the script that you
gave me..

I created a js file in my project itself - TimeoutTimer.js
and i referenced this on one of my page's HTML as reference it using <script language="JavaScript"
src="TimeoutTimer.js"></script>.

and i had following code in my page load
Session.Timeout = 10; //i am ust overriding this...

int intTimeOut = Session.Timeout * 100;

Global.strScript = "startClock();updateClock(" + intTimeOut.ToString() + ");
Page.RegisterStartupScript("timerScript", Global.strScript);

But the output that i am getting is the following displayed on my page as a string...i think the the javascript was not executed...woudl u please tell
me what is the problem since i am new to scripts..

startClock();updateClock(1000)


Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul | last post: by
27 posts views Thread by mrbog | last post: by
2 posts views Thread by Damien | last post: by
reply views Thread by joseph conrad | last post: by
14 posts views Thread by aroraamit81 | last post: by
7 posts views Thread by aroraamit81 | last post: by
1 post views Thread by Santosh | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.