我正在清理一些遗留的框架代码,其中大量的代码只是异常编码.不检查任何值以查看它们是否为空,因此会抛出并捕获大量异常.
我有但是大多数清理,有一些错误/登录/安全相关的框架,正在做Response.Redirect的,现在,我们正在使用AJAX的方法,我们得到的ALOT 的Response.Redirect"不能被称为在页面回调中." 如果可能的话,我想避免这种情况.
有没有办法以编程方式避免此异常?我正在寻找类似的东西
if (Request.CanRedirect)
Request.Redirect("url");
Run Code Online (Sandbox Code Playgroud)
注意,这也发生在Server.Transfer上,所以我希望能够检查我是否能够执行Request.Redirect或Server.Transfer.
目前,它只是这样做
try
{
Server.Transfer("~/Error.aspx"); // sometimes response.redirect
}
catch (Exception abc)
{
// handle error here, the error is typically:
// Response.Redirect cannot be called in a Page callback
}
Run Code Online (Sandbox Code Playgroud) c# asp.net response.redirect exception-handling asp.net-ajax