这一次给我带来了很多痛苦!对于我的应用程序,我使用的是110秒的全局ExecutionTimeout。一个特定的页面会生成大量未处理的异常,因为它包含一个FileUpload控件。
现在是问题.我知道如何使用以下声明限制web.config中的文件大小和执行超时。
<httpRuntime maxRequestLength="2097152" executionTimeout="600" />我的问题就在这里:
'Check file size
Dim fileSize As Integer
Try
fileSize = FileUpload1.FileBytes.Length
Catch ex As Exception
'Display message to user...
Exit Sub
End Try检查文件长度的过程非常频繁地抛出异常,而且在上面的try, catch中没有很好地捕捉到该异常,它似乎要遵从global.asax中应用程序级的异常处理。
我很确定我不能检查客户端的文件大小,我不想继续弹出maxRequestLength和executionTimeout,我所要做的就是捕捉页面上的超时并显示一条消息。这个是可能的吗?
编辑-
为了在这里更好地说明这个问题,请运行以下代码(假设您的默认executionTimeout是110秒)。
Try
system.threading.thread.sleep(120000)
Catch ex As Exception
response.write("Error caught!!")
Exit Sub
End Try确保已关闭调试。catch块不能工作,最终会出现一个未处理的System.Web.HttpException: Request timed out错误,这一点我还没有弄清楚呢?
发布于 2013-10-22 16:47:18
结果,页面上的代码并没有在这里直接抛出异常,因此它没有被try, catch捕获。当脚本执行时间过长时,应用程序会监视和干预,因此当异常在应用程序级别引发时,我们需要遵从global.asax。
解决方案包括在Global.asax Application_Error块中捕获错误,然后将错误类型附加到查询字符串中,将response.redirecting返回到原始页面。
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim exc As Exception = Server.GetLastError
Dim context As HttpContext = DirectCast(sender, HttpApplication).Context
Dim uri As String = context.Request.Url.PathAndQuery
If uri.Contains("users/account.aspx") Then
Response.Redirect(context.Request.Url.PathAndQuery & "&err=" & exc.GetType().ToString)
End If
End Sub然后,您可以签入页面加载中的任何err查询字符串值,然后相应地在页面上显示错误。
https://stackoverflow.com/questions/19521131
复制相似问题