Recently, the project encountered a strange problem: If the browser session is lost, click a button to trigger an Ajax method, a dialog box will pop up in the browser. The exception information is as follows:
After searching, my page inherits a basepage. CS file, basepage. check whether the session exists in the CS file. If the session does not exist, jump to the logon page (response is used here. redirect ()). It is precisely because of the existence of this jump code that an error is reported. The Ajax method cannot perform page Jump operations. If you want the Ajax method to jump to the page, configure it in the web. config file. Add the following code:
<System. Web>
<Httpmodules>
<Add name = "scriptmodule" type = "system. Web. Handlers. scriptmodule, system. Web. Extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Httpmodules>
</System. Web>
Sometimes you may say that this configuration information has been added to my configuration file. Why does the page still report an error?
This method only supports response execution in the CS file. the redirection of redirect () does not support server. transfer () and server. execute () forwarding, and response. write ("<SCRIPT> </SCRIPT>") Outputs a script jump on the page.
However, you can use response. Redirect () to jump to a specified page and write JS scripts in that specified page.
Of course, if you do not want to add this code in the configuration file, you can add the following JS script to the page file as you said on the Internet to handle the exception.
<Script language = "JavaScript" type = "text/JavaScript">
// When the Ajax page is used and the session is lost, a prompt is displayed and you are redirected
SYS. webforms. pagerequestmanager. getinstance (). add_endrequest (endrequesthandler); function endrequesthandler (sender, argS)
{
If (ARGs. get_error ()! = Undefined ){
If (ARGs. get_error (). Message. substring (0, 51) = "SYS. webforms. pagerequestmanagerparsererrorexception ")
Window. Location. Reload (); // handle the error when the session is lost. You can define it yourself.
Else
Alert ("Logon timeout. Please try again! "); // Handle other errors.
Args. set_errorhandled (true );
}
}
</SCRIPT>