Click here to Skip to main content
15,742,655 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
A manager got the same email 7000 times today and he's not smiling. HELP!

How can a web page without a loop, going into an infinite loop? (Asp.Net C#)

We have techs who download training material PDFs, DOCs etc.
The managers want to know what the techs are studying
so right before the download I send the manager an email.

A thousand downloads work fine, then one appears to "hang" (file size is random)

During this "hang" time, the same manager email is being sent endlessly
until the tech gives up waiting and cancels the download.

There are no code loops, I can't see how the browser would cause the loop...

To email, and leave the link page available, I use two pages.

Page 1 has asp:HyperLinks with a TARGET to open a new page.
That page is always Page 2 (while I pass PDF path).

Page 2 (looping) is simple: send the email, then response.redirect to the download file.
The tech sees a new page open and his download starts.

I have never been able to reproduce this for debugging.
I get no error in my try/catch or globally.

Thanks for any ideas out there!
Update 1: My code involved
(I was trying my best to keep the post short... but here's the core code if that helps)
Also the tech said, it may have happened when his IE browser allowed him to save before the download had completed. But I have not been able to reproduce the loop by that method.
Page 1: A HyperLink in a GridView
Pass the path/name to a page called "bounce"
<asp:HyperLink ID="hlBounce" runat="server"
    Text='<%# Eval("FileName") %>'
    NavigateUrl='<%# "~/private/training/courses/Bounce.aspx?pth="  +     Eval("FullPath") + "&nam=" + Eval("FileName")  %>'
    Target="_Blank" />

Page 2: Email and Redirect to PDF
protected void Page_Load(object sender, EventArgs e)
// Edited: Here I set my connection string, pull my parms from QueryString...
    if (sFilePath != "")
            // This EmailMgr method just builds text, sqls manager address, 
            // and calls a generic class that sends email
            string sResult = EmailMgr(sFilePath);
        catch (Exception ex)
            eh.SaveErrorText(ex.Message.ToString(), ex.ToString(), sFilePath); 
        Response.Redirect(sFilePath, false); // Used both true/false: same looping
    Response.End(); // trying in vain to stop loop...
Updated 19-Nov-13 7:51am
idenizeni 19-Nov-13 14:17pm    
Could the issue be related to a particular file? If so, could it be possible the particular file that caused this issue for the user has something in the filename that 'breaks' the redirect to sFilePath and thus causes the page to redirect back to itself which in turn causes the EmailMgr routine to be repeatedly called? Or, did the user manipulate the query params such that the redirect caused the page to call itself repeatedly? You may want to look at saving the filename in the viewstate or session variable to prevent users from manipulating the URL and thus breaking the redirect process.
Member 8774961 19-Nov-13 15:05pm    
Good thought...
But the two files that looped this morning have no spaces or special characters
(CM18TrainingGuidepart1.pdf, CM18TrainingGuidepart2.pdf).
Also all users report successfully reaching the file and beginning the download.
Thanks for thinking about this.

1 solution

No one can fix your code without seeing it. So, I can only dismiss your idea that a the source of an "infinite" cycle should be some loop in code. There is at least one more possible reason: recursion, which can be very indirect:[^],[^],[^].

And, in practice, it can be anything. Again, sorry for not solving your problem. I guess, it's hardly possible based on your information.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900