 |
|
 |
Hi,
I develop a lot of asp.net websites, and I came across this issue also, especially in combination with the concept of url-rewriting. The way I re-write the url's is done through regular expressions, and because I disabled the session (to work around the time-outs), the url was rewritten like crap. The SessionID kept putting itself inbetween my urls, so I disabled the session altogether in web.config like so:"Off" />.
Then I rewrote my application to store all global (application) variables in a static class. Then we had the issue of logging in. So when logging in (which used to require SessionState in my application) I put the following code:
System.Web.Security.FormsAuthentication.SetAuthCookie(tbUSERNAME.Text, false); Response.Redirect("~/Admin/Default.aspx");
And on top of the page which should be authenticated I put the following:
private string AuthenticatedUser = "";
protected void Page_Init(object sender, EventArgs e) { try { string temp = this.Page.User.Identity.Name; AuthenticatedUser = temp; } catch {
} if (String.IsNullOrEmpty(AuthenticatedUser) == false) { } }
Hope this is of any use to anyone. If you have questions, just ask!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
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 | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
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.
private void RegisterSessionKeepAlive() { try { int timeoutWindow = 30; int timeout = (this.Session.Timeout * 60000) - (timeoutWindow * 1000); string reconnectUrl = VirtualPathUtility.ToAbsolute("~/Common/SessionReconnect.aspx"); string startupScript = string.Format("window.setInterval('reconnectSession()', {0});\n", timeout); 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"); script.Append("var reconnectMax = 5;\n"); 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 | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
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 | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
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 | 2.00/5 (1 vote) |
|
|
|
 |