Click here to Skip to main content
14,767,355 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know the default upload max is 4MB, if we upload some file larger than this, the ugly error page will pop up.
I find somewhere the solution is enlarge the maxRequestLength is web.config. But I think it's not done, the users can always upload the file larger than the maxRequestLength, I want to know how can I pop up a message box when the upload length is exceed the limit, thanks!


In my asp.net website, I write some code in global.asax file, but it didn't work:
void Application_Error(object sender, EventArgs e)
{
    // Code that runs when an unhandled error occurs
    HttpException h = Server.GetLastError() as HttpException;
    if (h != null && h.WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
    {
        try
        {
            Server.ClearError();
                        Page page = HttpContext.Current.CurrentHandler as Page;
            if (page is Page)
            {
                page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('error');< / script>");
            }
        }
        catch (Exception)
        {


        }
    }

}
Posted

In html5 you can check the file size :
http://stackoverflow.com/questions/1601455/check-file-input-size-with-jquery/3937404#3937404[^]
based on error code you can redirect users to user friendly error page or you can
Application_BeginRequest
method and check the size. check both answers on below link
http://stackoverflow.com/questions/12748522/redirect-user-to-another-page-on-page-error[^]
   
v2
Hi Johnson,

You can set Limit in your Web Config

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="x" />
  </system.web>
</configuration>


where x is your max file size in KB.

Good Luck
   
Have a look on below links:
Link 1
Link 2
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900