views:

175

answers:

6

I have the following code pasted below. For some reason, the response.redirect seems to be failing and it is maxing out the cpu on my server and just doesn't do anything. The .net code uploads the file fine, but does not redirect to the asp page to do the processing. I know this is absolute rubbish why would you have .net code redirecting to classic asp, it is a legacy app. I have tried putting false or true etc. at the end of the redirect as I have read other people have had issues with this. Please help as it's driving me insane! It's so strange, it runs locally on my machine but won't run on my server! I am getting the following error when I debugged remotely. {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

(UPDATED) After debugging remotely and taking the redirect out of the try catch, I have found that the redirect is trying to get to the correct location but after it leaves the redirect is just seems to get lost. (almost as if it can't navigate away from the cobra_import project) back up a level to COBRA/pages. Why is this??? This has worked previously!!!

public void btnUploadTheFile_Click(object Source, EventArgs evArgs) 
    { 
        //need to check that the uploaded file is an xls file.

        string strFileNameOnServer = "PJI3.txt"; 
        string strBaseLocation = ConfigurationSettings.AppSettings["str_file_location"]; 
        if ("" == strFileNameOnServer) 
        {
            txtOutput.InnerHtml = "Error - a file name must be specified."; 
            return; 
        } 
        if (null != uplTheFile.PostedFile) 
        { 
            try 
            { 
                uplTheFile.PostedFile.SaveAs(strBaseLocation+strFileNameOnServer); 
                txtOutput.InnerHtml = "File <b>" + strBaseLocation+strFileNameOnServer+"</b> uploaded successfully"; 

                Response.Redirect ("/COBRA/pages/sap_import_pji3_prc.asp");

            } 
            catch (Exception e) 
            { 
                txtOutput.InnerHtml = "Error saving <b>" + strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString(); 
            } 
        } 
    } 
A: 

Try specifying an absolute address:

Response.Redirect("http://example.com/COBRA/pages/sap_import_pji3_prc.asp", false);
Darin Dimitrov
it's not an external website. It's an internal transfer within the same application.
jeff
What same application? Classic ASP and ASP.NET cannot be the same application.
Darin Dimitrov
you would have thought that, the .net pages are in a separate project, all in the same solution.
jeff
I just tried taking the response.redirect out of the try but still crashes.
jeff
How are those pages hosted in IIS? You must have a virtual directory for the .NET application. How about the asp pages? Where are they stored? Are they inside the same virtual directory?
Darin Dimitrov
the strange thing is this has worked previously and only recently stopped working.
jeff
@jeff Works-on-my-machine syndrome
Humberto
The application is running as a web app COBRA .NET pages are in a virtual directory Cobra_Import, the asp pages are running within the application COBRA i.e. COBRA/pages or COBRA/Cobra_import/.net pages
jeff
+1  A: 

Response.Redirect doesn't work very smoothly inside a try...catch block. See this question.

Humberto
A: 

You can try this :

Response.Redirect ("~/COBRA/pages/sap_import_pji3_prc.asp");

David
interesting... when i put that in it now says page cannot be found. Is this the problem that the redirect for some reason cannot find the page?
jeff
+1  A: 

crashing with what error? stack overflow (heh.. ironic) if that is the case you have infinite loop which would explain cpu spike, but this is not likely.

are you able to step through the code?

does the crash go away when you try redirecting to different addresses?

response redirect just sends a redirect header to the browser, which is than responsible for requesting the new address. I am guessing the new address is what is causing the crash. This is why putting try/catch around redirect wont work because the failiure is likely on the destination page.

provide more crash info and than we can help you further.

Sonic Soul
+1 for redirecting to a different address. (IOW, is the classic ASP page actually working properly on the server?)
Jason Berkan
not sure what you are asking, but asp can co-exist on same server as asp.net they are using different dlls.. asp.dll aspnet.dll to handle the request respectively. they are also using different configs as im sure you know.. global.asa vs global.asax so, redirecting to the other is fine.. you should just be aware that the sessions are separate. put some debug code in destination page to see what happens and IF it is hit as expected..
Sonic Soul
a great tool for you to debug this is Fiddler. it will show you what happens during and after redirect
Sonic Soul
i'm going to try and remote debug to see if i can get an error message.
jeff
I managed to setup remote debugging and got the following exception thrown {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
jeff
+1  A: 

Response.Redirect writes an HTTP response status and header to instruct the browser what the next page to request is, and then throws a specific exception in order to end the current request immediately and stop processing.

Catching the exception from Response.Redirect will cause the intended effect (immediately halting execution of the current request) not to happen.

Redirecting to an invalid URL will cause the browser to request an invalid URL and then not be able to continue. Invalid URLs in the HTTP Response Location: header include URLs missing schemes and hosts, so you need to put in the scheme (http or https) and the host (my.example.com). You can test out what Response.Redirect will do if you pass in something beginning with ~/ - you may be lucky and ASP.NET may be smart enough to translate that into the appropriate valid URL.

Justice
Tried that already, i put in "~/COBRA/pages/sap_import_pji3_prc.asp") and it fails. I used fiddler to confirm URLS, and it is transferring to the correct location : /COBRA/pages/sap_import_pji3_prc.asp. It's something to do with IIS I think redirecting from .net page to asp. I can't figure it out it's driving me nuts.
jeff
A: 

We've found that the error is related to the page running after the redirect. This question is irrelevant will create new question with current issue. Thanks everyone for your help. My current error is ASP error 424 that is being created after the following code: a

jeff