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

  • Home
  • SEARCH
  • 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 1074603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:09:13+00:00 2026-05-16T21:09:13+00:00

I am using a custom HTTPModule to check the size of the request being

  • 0

I am using a custom HTTPModule to check the size of the request being posted. If it is larger than a given size I would like to stop the request but still render the view with an appropriate error message.

I want to make it nice and simple to reuse so in my action perhaps having a ValidationAttribute on the model?

Has anyone done this before and have any pointers?

  • 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-16T21:09:15+00:00Added an answer on May 16, 2026 at 9:09 pm

    The issue is that there are parts of the request which may be required to display the page, so stopping the whole request means that you may not be able to display the view.

    In our case this was using the ValidateAntiForgeryTokenAttribute, this would throw an exception because you went to the action and the request didn’t contain the required data.

    There are a few solutions which strip out the files from the request, which means that asp.net doesn’t run out of memory, but this means that you are still dealing with the incoming stream and you have to put a limit on this somewhere

    <!-- Max 4MB -->
    <httpRuntime maxRequestLength="4960"/> 
    

    This is where you tell asp.net to throw a wobbly and not deal with the request, you can then catch the 413 error in the usual way and show an error page, or what ever. (the above is the default afaik)

    What we have done here is to add another setting, MaxContentLength, above this value and below “the wobbly” we can say “its too big” by checking the Request.ContentLength in a base controller and set a model error

    if (Request.ContentLength
            > Settings.Default.MaxContentLength * 1024) {
        ModelState.AddModelError("_Form", Resources.MaximumSizeRequestExceeded);
    }
    

    Now Model.IsValid will be false in my action

    This is not ideal, but with some explanatory text with size limits in… its workable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to
I need to write a custom UrlRewriter using a HttpModule, in the moment of
I want to implement an ISAPI filter like feature using HttpModule in IIS7 running
I have a custom list definition created via visual studio 2010. I would like
Background : I am currently using custom controls within my C# project (basic controls
I've been trying to switch from using PerlSetEnv to using custom configuration directives .
I am creating a installer in .NET and using custom actions for controlling installation.
I'm using a custom-built inhouse application that generates a standard set of reports on
I am using some custom controls one of which is a tooltip controller that
We are using a custom FTP application (which encrypts the files) for secure transfers.

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.