开发者

Redirect to classic ASP failing with "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack"

开发者 https://www.devze.com 2023-01-02 16:59 出处:网络
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

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. 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.

Update

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(strBaseLo开发者_StackOverflow中文版cation+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(); 
            } 
        } 
    } 


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


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.


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.


Try specifying an absolute address:

Response.Redirect("http://example.com/COBRA/pages/sap_import_pji3_prc.asp", false);


You can try this :

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消