Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 555789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:51:05+00:00 2026-05-13T11:51:05+00:00

I am developing an ASP.NET site with C# on IIS 7, but I hope

  • 0

I am developing an ASP.NET site with C# on IIS 7, but I hope for an answer that will apply to IIS 6 as well. Part of this site is the ability to upload up to 5 images at a time. I have a nice algorithm to resize the image that is uploaded to my optimal size and ratio.

So the only real size limitation I have is during the initial upload. I have modified my web.config to raise the packet limit from 4MB to 32MB. For the most part this takes care of my issues.

My question comes in the rare cases that a user tries to load more than my limit. I can raise the limit, but there is always a chance a user can find 5 files that are bigger. If a user selects files that are bigger, my try/catch block does not handle the error. The error is coming from IIS.

So how can I catch the error in C# code where I can make modifications to my ASP.NET interface to inform the user to select smaller files instead of them seeing a nasty error screen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:51:05+00:00Added an answer on May 13, 2026 at 11:51 am

    You can get access to the exception when the request length is exceeded. Use an HttpModule, and add a handler for the Error event.

    The exception is of type: System.Web.HttpUnhandledException (with an InnerException of type: System.Web.HttpException).

    To catch this exception, add this to your web.config:

    <httpModules>
        <add name="ErrorHttpModule" type="ErrorHttpModule"/>
    </httpModules>
    

    And add this class to your App_Code folder:

    public class ErrorHttpModule : IHttpModule
    {
        private HttpApplication _context;
    
        public ErrorHttpModule() {
        }
    
        private void ErrorHandler(Object sender, EventArgs e)
        {
            Exception ex = _context.Server.GetLastError();
    
            //You can also call this to clear the error
            //_context.Server.ClearError();
        }
    
        #region IHttpModule Members
    
        public void Init(HttpApplication context)
        {
            _context = context;
            _context.Error += new EventHandler(ErrorHandler);
        }
    
        public void Dispose()
        {
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ASP .NET web site that will allow users to view and
I'm developing an ASP.NET site off of my Windows XP IIS Installation, and whenever
I'm developing an ASP.NET application for an intranet site that is using Windows/NTLM/WIA/whatever authentication.
I am developing a site (ASP.Net based) that, besides other features enables the users
We are developing an ASP.NET MVC web app that will be hosted on Windows
I have an ASP.NET site that I'm developing. The layout is pretty basic. The
I am developing a web site using ASP.NET MVC. The site will be similar
Before you answer, this question is complicated: We are developing in asp.net / asp.net
I am developing a site using asp.net MVC. I have used AJAX for paging,sorting
I am using ASP.NET MVC for developing a web site. I am using jquery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.