I'm looking at the IIS 7 Request Limits <requestLimits>
setting, specifically maxAllowedContentLength
and was wondering if this could be applied at the ASP.NET Routing level? I am working in an ASP.NET MVC 3 project that allows for file uploads, but I want to only allow the larger requests for those specific routes.
This question is similar to the unanswered Can I increase maxRequestLength of ASP.NET request for MVC Controller Action with additional parameters?
An answer to Where do I catch and handle maxAllowedContentLength exceeded in IIS7? seems to imply I can do something like this, but I was looking for confirmation or other ideas.
protected override void OnError(EventArgs e)
{
Exception err = Server.GetLastError();
if (err is HttpException)
{
if ((err as HttpException).WebEventCode == 3004)
{
// check to see if upload request and let through
Server.Transfer( Context.Request.Url.LocalPath );
return;
}
}
base.OnError(e);
}
You could put the <requestLimits>
element in a <location>
tag for the (fake) virtual directory corresponding to that route.
I don't know of any better solution.