0

I have an ASP.NET 4.5 web form running C# code behind on a server. A specific form often takes some time to finish while it updates and changes various database records. However, if the user closes the tab or tries to reopen the web form, it will try to check the users status in the database and fail when those later change due to the first running process.

The need is to track this specific instance of the process and user, and if it is still running, prevent the page from loading fully or redirect. I was hoping to find and store some user and process information on a cookie and then simply check for this each time on page_load. I was not able to find these variables/properties.

Am I going about this the right way, and if so, how can I accomplish this?

Thanks!

  • "A specific form often takes some time to finish" how much time are we talking about? You probably need to consider putting up some sort of message while the page is disabled. There is nothing you can do that will stop the user from closing the browser (the user will lose connection with the current session). – DaniDev Jan 05 '18 at 17:22
  • It depends on the number of courses selected and the number of student enrollments each of these courses have. So the form often take 30 to 110 seconds. I have changed the server timeout to accommodate this. The issue is that the link to this form is on another page. The link opens the landing page of the web form. So I couldn't exactly disable the link each time it is clicked, or each time a user clicks submit. Unless I am missing some obvious work around? – Terrance Smith Jan 05 '18 at 19:22
  • From you description it sounds like you are having a issue on a postback "A specific form often takes some time to finish". Do you mean it takes time to load? – DaniDev Jan 08 '18 at 17:16
  • It is just an intense process. The form can take any number of courses, any number of students in each, and merges them together. So it may be churning through courses and students for a couple of minutes. During that time it is not uncommon for a person to close the tab and open it again. If the process is still running, that person may get an error when an enrollment changes. Short description: the first process is still doing work when they try to open a new form and start another process. – Terrance Smith Jan 08 '18 at 21:30
  • I guess I didn't make my question clear. Does this "takes some time to finish" do you mean on initial load or "postback" . "Postback" means that the form has posted ("sent") something back to the code behind and is (partially) re-loading. – DaniDev Jan 08 '18 at 22:18
  • On postback. On postback is where the process is taking the time to process. The web form has submitted to the server and the server is doing work. The actual error will happen on page load when it tries to gather actively changing information. – Terrance Smith Jan 08 '18 at 22:55
  • "The actual error will happen " Ok, so you are registering an error. What is that error ? and please post the code that is referenced in (causing) the error – DaniDev Jan 08 '18 at 23:00
  • I guess I am not making the issue very clear. There is no registered error, just an exception. Posting enough of the 3000 lines of code to show the issue is not possible. Let me walk through the process. An instructor has two courses and uses the process to merge them into one. This deletes the extra course. While this is happening, if they open the form again, it looks to see what they are enrolled in. When the extra course is found, then the first process deletes it, the newly opened form gets confused when that course is no longer accessible. Exception when course found is now null. – Terrance Smith Jan 09 '18 at 16:04
  • error is another word for "exception". If you want help post the stack trace and the code associated with that exception. – DaniDev Jan 09 '18 at 17:08
  • Error and Exception are different. https://stackoverflow.com/questions/2435152/what-is-the-difference-between-an-error-and-an-exception-in-net The exception is a index out of bounds error caused by the program looking for an instance of an enrollment that is no longer there. Posting this would not help. I have made the question extremely clear. Is there an process ID that I can reference in conjunction with the user to determine if the server is still running that request. No need to talk about existing code or errors. – Terrance Smith Jan 09 '18 at 17:24
  • I have found a different solution that seems to be working. Instead of trying to check the existing process, which I would still love to do. I made it so that the page would warn before leaving if the page has not yet shown its confirmation or error pages. The tools for this were all JQuery and can be found in this posting. https://stackoverflow.com/questions/10397432/how-to-capture-when-a-user-is-leaving-asp-net-page-unexpectedly – Terrance Smith Jan 09 '18 at 17:28

1 Answers1

0

I was not able to find the exact solution I was looking for. At the moment, I cannot see any way to find a server side identification id of the process.

Instead, I referenced How to tell if a page unload in ASP is a PostBack and made it so that the page would warn when being unloaded before the confirmation screen is shown. As long as the form opens to the same named tab, the user would be given the warning screen and given a confirmation before they could close or reload a new web form instance.