 |
|
 |
This giving me a new idea, how to make a trigger with client side scripting before the session timeout.. So, i can use the session data before it clear/destroy to update the DB (IS_LOGIN)
IS_LOGIN is a flag, where it inform when the user login/not login.. to make sure the user cannot do double login from other location..
Hehe.. Once again Thanks...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was wandering if it would be possible to create me a simple program to stop my online banking logging me out or do you know of such a program already in existence. Maybe just tell it to activate the browsers refresh button would do fine. I am not a programmer at all yet so i wouldn't be able to create this myself.
thank you so much in advance
jsmith07611@gmail.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
For those of you using ASP.NET 2.0 with MS AJAX, here is an update for you. Some of you probably don't know that AsyncPostBacks (those caused by UpdatePanels and what not) cause you to do a little more work when registering scripts via the Server-Side. Also, keep in mind that this WILL WORK even when you don't have a ScriptManager on the Page.
Just change the path to your "Reconnect.aspx" page (see the bold text below) to reflect your site structure. I use this script in my MasterPage and call it each time the Page Loads. Always register this script everytime the page loads, it's smart enough to handle AsyncPostBacks and that's what you want.
/// <summary> /// Registers a Script with the Client-Side code to keep a user Session alive /// </summary> /// <remarks> /// Adapted from: http://www.codeproject.com/KB/session/Reconnect.aspx /// </remarks> private void RegisterSessionKeepAlive() { try { // NOTE: Everything needs converted to milliseconds int timeoutWindow = 30; // Number of seconds before session will timeout to fire a simulated PostBack to renew Session int timeout = (this.Session.Timeout * 60000) - (timeoutWindow * 1000); // if (System.Diagnostics.Debugger.IsAttached) timeout = 10000; // For Testing, comment if not needed string reconnectUrl = VirtualPathUtility.ToAbsolute("~/Common/SessionReconnect.aspx"); string startupScript = string.Format("window.setInterval('reconnectSession()', {0});\n", timeout); //Set to length required string scriptKey = "SessionReconnectScript"; string startupScriptKey = "SessionReconnectStartupScript";
ScriptManager sm = ScriptManager.GetCurrent(this.Page); if (sm != null && sm.IsInAsyncPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), startupScriptKey, startupScript, true); else { if (!Page.ClientScript.IsClientScriptBlockRegistered(this.Page.GetType(), scriptKey)) { System.Text.StringBuilder script = new System.Text.StringBuilder(); script.Append("var reconnectCount = 0;\n"); // Number of Reconnects script.Append("var reconnectMax = 5;\n"); // Maximum Reconnects script.Append("function reconnectSession(){\n"); script.Append("\treconnectCount++;\n"); script.Append("\tif (reconnectCount < reconnectMax){\n"); script.Append("\t\twindow.status = 'Session Refreshed ' + reconnectCount.toString() + ' time(s)';\n"); script.Append("\t\tvar img = new Image(1,1);\n"); script.AppendFormat("\t\timg.src = '{0}';\n", reconnectUrl); script.Append("\t}\n"); script.Append("}\n"); Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), scriptKey, script.ToString(), true); }
if (!Page.ClientScript.IsStartupScriptRegistered(this.Page.GetType(), startupScriptKey)) Page.ClientScript.RegisterStartupScript(this.Page.GetType(), startupScriptKey, startupScript, true); }
} catch (Exception) { throw; } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Tim
I got this to work but only after I wrapped the Javascript sections in strScript = "<script type='text/javascript'>;" ..... strScript += "</script>"
Prior to that it just printed the startupScript on my page
JohnG
To the brave and faithful all things are possible! Cardiff 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Are you sure you specified "true" as the last parameter of the "RegisterStartupScript / ScriptBlock" methods? The scripts components automatically add those "<script>" tags in there for you. Granted, I am running on ASP.NET 2.0 SP1.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You're right - I hadn't set the last param to True. I was translating your code into VB and didn't see the last parameter because the line was too long and I couldn't scroll across in IE7.
To the brave and faithful all things are possible! Cardiff 2006
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
For some reason my app times out after approximately five minutes even if I have set the session timeout to 20 minutes. Is there a performance hit or some other reason why I should not set the timeout to five minutes (or even one minute) and set the reconnectMax to a high value like 100?
thanks Thomas
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
We're currently seeing this issue in another app (one I haven't added this feature to). I'm not sure why Sessions timeout like this (it could have something to do with the fact that ASP.NET does not renew the Session timeout until you have had some activity on the site after the timeout has reached it's half-way point). But I don't see a problem with your approach.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I can keep the session alive for approx. 17 minutes by setting the refresh-timing to one minute, which is fine. But as soon as it reaches 18-20 minutes, the session times out (the session timeout is 20 minutes). So the five minute issue seems be solved - thanks.
best regards Thomas
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
For some reason the reconnect page still got cached at the client. I can see this with fiddler, I only see one request.
Setting the output cache didn't solve the problem. Therefore I did the following in the javascript and that worked: Reconnect.aspx?count=' + count
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In my opinion (and this is just my opinion) using an ajax call to keep the session alive would be a more elegant solution.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi,
I have an ASP.net page that takes over an hour and sometimes more to execute. I have set the session timeout to 40 minutes and have the following java script to send mesg to server just to prevent timeout from occuring.
<script type="text/javascript" language="javascript"> function Reconnect(){ var img = new Image(1,1); img.src = "New.aspx"; } window.setInterval("Reconnect();", 600000); //Set to length required
</script> After the page has been running for more 60 minutes, I get a Page Cannot Be Displayed error. This error occurs in IE 6 , but the page executes without a problem in Firefox.
I would like to know what is actually causing the error and why is my script not working for IE. Is it an IE setting that can be changed or something else?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Firstly let me say that a page request that takes an hour to process seems like it should be done in another way. My suggestion would be to use a background thread for processing with an AJAX timer request or auto page refresh to get status on the thread processing the request. You will see this type of page on travel sites when they request flight info for example.
this link has some info on asynchronous pages in asp.net http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/
Also see this code project article: http://www.codeproject.com/KB/aspnet/asynctransactionhandler.aspx[^]
you will also find many other examples if you google "ASP.NET background threads" or "ASP.NET asynchronous page requests".
The code you have used from my example for keeping session alive is not really any good if the browser is waiting for the complete response longer than the session timeout value as the javascript will not fire until the page is loaded.
I hope this helps.
Regards
Richard
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Is that the name of the page this code goes into? I'm guessing it is, but I would like to be sure.
Thanks much!
Been there, done that, forgot why!
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
 |
Good grief! That was supposed to be what is Reconnect.aspx.
Now I finally got the structure of this solution.
However, I tried it and it prints the redirect, but it don't fix the problem.
This is in Visual Studio 2003, tested on an XP test server, using IIS V 6.
I've messed with every timing value that even remotely sounded like what I needed to try. I've tried everything I can find in goggle, This problem has continues for two weeks of frustrationf or me.
Such persistant problems are like a flame and the programmer is the moth (I'm the moth) that is held helpless in the fire by demands to pull this rabbit out of the hat. In this case, it's Microsoft told them it can be done, but it's me that has to implement what I begin to think is an impossible task.
Here is the code in the form I want to keep alive..
Any clues why this does NOT work?
Deadfrankenstein.aspx ....
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.AddKeepAlive() ' keep alive End Sub
Private Sub AddKeepAlive()
Dim int_MilliSecondsTimeOut As Integer = (10 * 60000) - 30000 ' Refresh every 10 minutes. Dim str_Script As String = "<script type='text/javascript'> var count=0; " str_Script &= " var max = 7; " str_Script &= " function Reconnect(){" str_Script &= " " str_Script &= " count++; " str_Script &= " if (count < max) " str_Script &= " { " str_Script &= " window.status = 'Link to Server Refreshed ' + count.toString()+' time(s)' ; "
str_Script &= " var img = new Image(1,1); "
str_Script &= " img.src = '~/Reconnect.aspx'; "
str_Script &= " } " str_Script &= " } " str_Script &= " " str_Script &= " window.setInterval('Reconnect()'," & int_MilliSecondsTimeOut.ToString() str_Script &= " ); " str_Script &= "</script>"
Me.Page.RegisterClientScriptBlock("Reconnect", str_Script)
End Sub
This is the content of Reconnect.aspx ...
<%@ OutputCache Location="None" VaryByParam="None" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html> </html>
Been there, done that, forgot why!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I fixed the timout issue...
In the login script was code that was making a call to FormsAuthenticationTicket and the third parameter is the time from now for the cookie to expire. Editing that fixed my problem!
Been there, done that, forgot why!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
    Hai I want to develop a website, which would work like mail server . just like yahoo and google.com please help me in knowing what are the requirements and how it will work .
Yogendra Dubey
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Not sure about the relevance of your question here?
Good luck getting someone to do your work for you too.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
just posted this as a reply to a question on forums.asp.net.
This alternative is a lot smoother if you use Ajax but works without is well.
You need to use a master page and sliding session expiration, or at least it's a lot easier that way. Of course you could jam a timer control in every page, but master pages are pretty nice for this and for other stuff as well. Well, in my master I page add:
<asp:Timer ID="tmCheckStatus" Interval="1800000" runat="server">
Where the Interval (remember it's ms and not seconds) should be your session timeout minus at least 10 seconds. I prefer to go with 30 seconds to one minute before session expiration, depening on what I want to do when session is closing expiration. The 10 seconds is just because your session sometimes expires before the expiration you've set, butusually not ore than 10 seconds earlier. Do a little testing on this. Ok, now that I've got the timer control ticking, add a code behind to handle the tick of the timer. Protected Sub tmCheckStatus_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmCheckStatus.Tick If b2bGlobal.isUserOnline = False Then 'This is if you use forms authentication 'but I'd say it works equally fine for 'normal' sessions 'Or you can fire a popup or redirect to a page asking the users 'if they want to stay online FormsAuthentication.SignOut() FormsAuthentication.RedirectToLoginPage() End If End SubWell, that's how I solve all annoying session timeouts and it's really easy. You can even set the timer interval to be (your session timeout value)/6 or some other number. For each tick you can change a picture or something like that, showing the ammount of time the user has left before automatic redirection occurs. It's nice for them and a cool feature for oneself, although one should take care not to let this sucker tick to much, as it could eat up server resources.
www.pixer.se
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Thanks for sharing but sorry Timer control cant be used without AJAX support installed. So it will be a lot of work on all fronts, testing/deployment/configuration, for AJAX overhead if its not there already.
Thanks
Abbas
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |