C # Call the response. Redirect method to trigger an exception

Source: Internet
Author: User

When writing a user verification function in the background today, You need to perform different page jumps based on the user's different permissions. The jump statement used is as follows:
Response. Redirect ("logonin. aspx ");

 

However, the following exception is always prompted:Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

I checked it on the Internet and found it was a method problem. I used the overload method response. redirect ("logonin. aspx ", false); .
the following are the reasons for the query (not too familiar ......):
response. the end method stops page execution and converts the execution to the application_endrequest event and response in the event pipeline where the Program is applied. the Code line after end is not executed. This problem occurs in response. redirect and server. in the transfer method, both methods call response internally. end
the solution is as follows:


(1) For response. end:
Call applicationinstance. completerequest instead of response. End to skip the code execution of the application_endrequest event.

 

(2) For response. Redirect:
Use the overload response. Redirect (string URL, bool endresponse) to pass false to the endresponse parameter to cancel internal calls to response. End. For example:
Response. Redirect ("nextpage. aspx", false );
If this solution is used, the Code following response. Redirect will be executed.

(3) For server. Transfer:
Use the server. Execute method instead.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.