954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Redirect to loginpage on Session timeout

Hi

I have found the following code for Redirecting the user to loginpage on Session timeout :

///////////
Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

Response.Write("Wait for session to timeout..")

End Sub

////////

I am trying to use the same code in C#, but I get errors in the line:

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")

The errors I get are as below and all are in the same above line:

) expected
; expected
; expected
Invalid Expression Term')'
; expected

Please somebody let me know how to rectify the error.

Thanks
Sandy

sandy2005
Newbie Poster
7 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 
Hi I have found the following code for Redirecting the user to loginpage on Session timeout : /////////// Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");") Response.Write("Wait for session to timeout..") End Sub //////// I am trying to use the same code in C#, but I get errors in the line: body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");") The errors I get are as below and all are in the same above line: ) expected ; expected ; expected Invalid Expression Term')' ; expected Please somebody let me know how to rectify the error. Thanks Sandy



Hi Sandy,
try the following code.
[HTML]
string str = "window.setTimeout(window.location.href='login.aspx'," & "(Session.Timeout * 60 * 1000) + 5000);";
body.Attributes.Add("onLoad",str )

[/HTML]
Thanks,
Kedar

kedar_challa
Light Poster
47 posts since Nov 2005
Reputation Points: 10
Solved Threads: 1
 

In c# you can't use "", you must use \". Also you forgot to add a ; at the end of the line. The correct code is:

body.Attributes.Add("onLoad", "window.setTimeout(\"window.location.href='login.aspx'\"," & (Session.Timeout * 60 * 1000) + 5000 & ");");

mvalid
Newbie Poster
1 post since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You