Skip to content

Instantly share code, notes, and snippets.

@pjvds
Created January 12, 2012 14:59
Show Gist options
  • Save pjvds/1600980 to your computer and use it in GitHub Desktop.
Save pjvds/1600980 to your computer and use it in GitHub Desktop.
FileUploadModule
public class FileUploadModule : IHttpModule
{
private const int _maxUploadSize = 1337;
public void Init(HttpApplication context)
{
context.BeginRequest += handleBeginRequest;
}
private void handleBeginRequest(object sender, EventArgs e)
{
var app = sender as HttpApplication;
var hasBigFiles = app.Request.Files.OfType<HttpPostedFile>()
.Any(f => f.ContentLength > _maxUploadSize);
if (hasBigFiles)
{
app.Response.StatusCode = 413;
app.Response.StatusDescription = "Request too large, squeeze it a bit more and try again!";
app.Response.End();
app.CompleteRequest();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment