Created
January 12, 2012 14:59
-
-
Save pjvds/1600980 to your computer and use it in GitHub Desktop.
FileUploadModule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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