The page will closed & saved after a few minutes - asp.net

My application is in Asp.net coded C#.
My requirement :
If someone has opened his page and didn't do nothing, then after 5 minutes the page will be closed and the changes will saved.
(this feature is exists in bank pages or another pages with protection)
Suggest how can i achieve the needed result.

You will need to use some client-side scripting to accomplish this. In your script you will need to use: setTimeout to set a timer to go off after 5 minutes of inactivity. (The timer should get reset whenever the user is actively doing something). When the timer goes off, call a function to postback to do a "save and exit".
Like #CodeOfChaos says Javascript might not let you close the browser. In my opinion it would be better to redirect the inactive user to a page telling them "Your changes have been automatically saved and you have been logged out."

Related

Active sessions on specific page

I'm aware of how to get a total count of active sessions for your application but is it possible to get a count of active sessions on a specific page?
For example if you had 2 users currently viewing 'page.aspx' then it would report 2 users active for this page.
I'm only aware of being able to query the current session in codebehind by using Page.Session
You can never know for certain if someone is viewing a page or not: the web is both disconnected and stateless.
The technique is, on every request, to log the page requested; every time that user (uniquely identified, somehow) moves to another page then their "last page requested" is updated, along with a timestamp, you might assume that if no subsequent request is made after say, 5 minutes, then they've closed the browser window.
An alternative is to use a Javascript poller or window event handler, but that's unreliable and you must never depend on this in your application.

Page hangs when leaving it for a while using ASP.NET Ajax

I'm working on a business application using ASP.NET Ajax , NHibernate and Spring.Net, I've got an annoying problem. The problem is that when I leave page for about 5 minutes and then return back and try to make any action that posts back, it displays wrongly (if there are controls hidden by style it became visible). In addition, the page didn't post back to the server.
Also the problem happens when opening two different tabs, different pages (Each page uses session but different keys )
Thanks in advance
As you describe the problem, its sounds that connect the content of the page with the user cookie and session, and when the session expired the application did not take care to recreate it.
So the post back fail because the session data have been lost when the page ask for them / need them to work and display correct the results.
This is the issue that I diagnose, how you fix that is up to you :)
Possible solutions
Change the logic of the page creation.
While the user is on page do not let the session ends (not good practice)
Store the user data of the page, on a database - connected with the user, and delete it after some days if not have been updated.

VB.net starting a new session

While Ive seen plenty of examples in PHP, can't seem to find one in VB, I want to know if this is even possible.
I have a page, a session starts on page load (using global.asax) the user may not move from (or interact with) that page for a long while and I dont want to increase the session timeout. When the session times out after say.. 20 minutes, I want to start a new one, without moving from the page.
I also don't want constant keep-alives
I want to do it via another method (timer, button press...)
Is this even possible?
If you want to extend the session without a constant keep-alive, and prefer the user to click a button, or base it on a timer, then I would advise that you use fire an AJAX request to the server and not expect any type of a response. Simply doing so will keep the session alive. You can fire this request on any of your preferred criteria using javascript/jquery.

how to intercept processing when Session.IsNewSession is true

I have a small 4-page application for my customers to work through. They fill out information. If they let it sit too long, and the Session timeout out, I want to pop up a javascript alert that their session has expired, and that they need to start over. At that point, then redirected to the beginning page of the application.
I'm getting some strange behavior. I'm stepping through code, forcing my Sessioni.IsNewSession to be true. At this point, I write out a call to Javascript to a Literal Control placed at the bottom of the . The javascript is called, and the redirection occurs.
However, what is happening is.. I am pressing a button which is more or less a "Next Page" button and triggering this code. The next page is being displayed, and then the Alert and redirection occurs. The result I was expecting was to stay on the same page I received the "Timeout", with the alert to pop-up over it, then redirection.
I'm checking for Session.IsNewSession in a BaseClass for these pages, overriding the OnInit event.
Any ideas why I am getting this behavior?
Thanks!
There multiple ways u can do this. Have hava Script timer as per u session timeout (Default is 20 min). After 19 min just rasise a alert on client and submit the page to the same page to refresh. This may not good option given user would have entered lot of stuff already
Or other way is don't session time out this page. U can do this on back ground just refresh the page after 19 min (U can do this by placing one div and iframe or image request on the server.). This might be good experiance for the user the reason is he don't have to enter the content again. Talking to u client giving this kind of option is worth sometimes.

Please wait dialog & downloading files in asp.net

In my ASP.Net application I have a requirement that when a user clicks on an UI element we generate a PDF for them which they can download. This is currently implemented by doing a form post to an ashx page. This page essentially inspects the form and then executes the correct server side page which either results in HTML or a PDF document of that pages HTML.
On the client I know ahead of time if we are going to be getting a PDF or HTML, when its an HTML I open a new window and direct the form post to that window and all works well. When its a PDF I don't change the target for the form and it remains on the current page.
This works, the user is presented with a save dialog, and the current page is not changed or lost.
The problem I have is that generating the PDF takes anywhere from 1-15 seconds. What I want to do is popup a please wait dialog. Displaying the popup is going to be easy, what I am not sure of is how do I know to close the popup? The popup will be a div in the current page.
The popup can have a client side timer which polls the server for task completion. The long running server task should update the progress in a database table or a server cache object which can be accessed by the polling service.
Couple of old articles from MSDN magazine. You should be able to use the same concepts with newer libraries like asp.net Ajax.
Reporting Task Progress With ASP.NET 2.0
Simplify Task Progress with ASP.NET "Atlas"
just have some javascript on the client side and let it show some animated GIF for 1-15 seconds (your choice) and close itself after the designated time.
Gulzar's suggestion was spot on. I have a simple ajax enabled wcf service which checks a session variable. My ashx page sets the variable to false when it starts processing and then true when its done.
I think there might be a race condition if the client checks before we set the session item to false; however, there are ways around that if we modify the service to set the session item to false after a client gets an im done response.
The tricks is still going to be figuring out what the intervalon the client should be. If we set it to low the user could save the file and then see the still processing message. I'm debating myself between half a second and a second. Anything less then a half a second seems unnessecary.
You said:
When its a PDF I don't change the
target for the form and it remains on
the current page.
If that is the case then the original page will be gone when the PDF is opened. In that situation I would have a loading animated gif and open it using Javascript into a div tag overlaying the rest of the page. You would not need to close it, so no timer or polling needed. It would just be gone when the page is gone.

Resources