【问题标题】:Capture data on request timeout在请求超时时捕获数据
【发布时间】:2012-02-17 09:58:25
【问题描述】:

我在处理我的网络应用程序中的文件上传的 ashx 页面上遇到很多超时。有没有办法可以捕获超时并记录一些有关上传的数据,以帮助我更好地了解问题所在?

记录器看起来像这样,我只需要将它附加到超时异常!

Private Sub LogTimeoutException(context As HttpContext)
    'Gather the data
    Dim sb As New StringBuilder()
    sb.AppendLine(String.Format("Toal files: {0}", context.Request.Files.Count))
    For Each f As HttpPostedFile In context.Request.Files
        sb.AppendLine(String.Format("{0} ({1}): {2}", f.FileName, f.ContentType, f.ContentLength))
    Next

    'Log it
    Dim l As New BitFactory.Logging.FileLogger(context.Server.MapPath("~/timeoutlog.txt"))
    l.LogInfo(sb.ToString())
End Sub

【问题讨论】:

    标签: asp.net web-services file-upload timeout ashx


    【解决方案1】:

    try catch 不起作用的任何原因?

    Private Sub LogTimeoutException(context As HttpContext)
        Dim sb As New StringBuilder()
        Try
            //gather the data
            sb.AppendLine(String.Format("Toal files: {0}", context.Request.Files.Count))
            For Each f As HttpPostedFile In context.Request.Files
                sb.AppendLine(String.Format("{0} ({1}): {2}", f.FileName, f.ContentType, f.ContentLength))
            Next
        Catch he As HttpException    
            //Log it
            Dim l As New BitFactory.Logging.FileLogger(context.Server.MapPath("~/timeoutlog.txt"))
            l.LogInfo(sb.ToString())
        End Try
    End Sub
    

    【讨论】:

    • 异常不是由 LogTimeoutException 方法抛出的,它是在达到内置超时限制时(90 秒)在 ashx 页面的某处抛出的。
    • 只需在 ashx 页面的正文中捕获相同的 HttpException。从那里进行日志记录。
    • 好的,我在 ASHX 页面中设置了一个用于日志记录的处理程序,现在如何测试它?有什么好方法可以模拟请求超时?
    • 您可以使用 Server.ScriptTimeout 将页面超时时间降低到几分钟。然后使用 Thread.Sleep(x) 其中 x 是直到超时的秒数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2011-02-26
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多