handling Application_Error in Global.asax doesn't seem to work although it was suggested by someone from Microsoft:
http://groups.google.com/groups?selm=GvCd%248VECHA.1816%40cpmsftngxa08&oe=UTF-8&output=gplain
see the discussions herehttp://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OnZOezyuCHA.2380%40TK2MSFTNGP11

解决方案 »

  1.   

    我记得有个属性是控制上传文件大小的啊~系统定义默认是4M的
    要是要上传大的文件就是设置
    <httpRuntime maxRequestLength="8192/"/>
    这里设置为8M
      

  2.   

    try to catch the error in Application_Error in global.asax:Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
      Dim AppEx As Exception = Server.GetLastError()
      If AppEx.Message.CompareTo("Maximum request length exceeded.") = 0 Then
        'this is an overlimit upload
        'clear the error out
        Server.ClearError()
        'redirect to my error page
        Response.Redirect("errorpage.aspx")
      End IfEnd Sub
      

  3.   

    这是个我以前用vb.net做的上传程序,你可以参考参考,里面有文件大小的获取
    Public Class uploadfile
        Inherits System.Web.UI.Page
        Private path1 As System.IO.Path
        Protected WithEvents AnswerMsg As System.Web.UI.WebControls.Panel
        Protected WithEvents FileUploadForm As System.Web.UI.WebControls.Label
        Protected WithEvents FileLength As System.Web.UI.WebControls.Label
        Protected WithEvents FileType As System.Web.UI.WebControls.Label
        Protected WithEvents filename As System.Web.UI.WebControls.Label
        Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm    'Protected WithEvents Component11 As WebApplication2.Component1
        'Private components As System.ComponentModel.IContainer
        Private directory1 As System.IO.Directory#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub
        Protected WithEvents ioFile1 As System.Web.UI.HtmlControls.HtmlInputFile
        Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
        '不要删除或移动它。
        Private designerPlaceholderDeclaration As System.Object    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
        End Sub    Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
            Dim lstrfilename As String
            Dim lstrFileNamePath As String        lstrfilename = Me.ioFile1.PostedFile.FileName '得到文件的目录信息
            lstrfilename = path1.GetFileName(lstrfilename) '返回文件名
            If (Not directory1.Exists("d:\dd\")) Then
                directory1.CreateDirectory("d:\dd\")
            End If
            Dim filenamearray(100) As String
            Dim i As Integer = 0
            Dim exists As Boolean = True
            filenamearray = directory1.GetFiles("d:\dd\")
            Do While i <> filenamearray.Length - 1
                If filenamearray(i).ToString = "d:\dd\" & lstrfilename Then
                    exists = False            End If
                i = i + 1
            Loop
            If exists = True Then
                FileUploadForm.Visible = False
                lstrFileNamePath = "d:\dd\" & lstrfilename
                ' 得到上传目录及文件名称 
                Me.ioFile1.PostedFile.SaveAs(lstrFileNamePath)
                '上传文件到服务器             ' 获得并显示上传文件的属性 
                filename.Text = lstrfilename
                ' 获得文件名称
                FileType.Text = ioFile1.PostedFile.ContentType
                ' 获得文件类型
                FileLength.Text = CStr(ioFile1.PostedFile.ContentLength)
                ' 获得文件长度
                FileUploadForm.Visible = False
                AnswerMsg.Visible = True
                ' 显示上传文件属性
            Else
                Me.FileUploadForm.Text = "此文件名已存在!!"
                FileUploadForm.Visible = True
                AnswerMsg.Visible = False        End If
        End Sub
    End Class