views:

100

answers:

1

How do I set maxAllowedContentLength value per action?

I have a few actions that used to upload files, each one needs a different maxAllowedContentLength value.

It make sense that we don't want to use action filters as we want to filter this request at IIS level. On the other hand, action filter is the best solution from coding perspective, as they coming after the routes, so I the routes change, it continue work.

In IIS6 I know we can use <location> tag to specify maxRequestLength to a specific location. I don't know how to use this approach on IIS7, and I don't like this approach, since the url routes are hand coded in the web.config.

What is the best solution to solve this problem?

A: 

Create a separate virtual site for the area you want different filtering.

Then run this command on your IIS server. (replace [IISWebsitename])

C:\Windows\System32\inetsrv>appcmd set config "[IISWebsitename]" -section:requestFiltering -requestLimits.maxAllowedContentLength:100000000 -commitpath:apphost

That enables 100,000,000 bytes of upload data at a time for that one web site.

Carter
I don't like using the Command-Line. But if I'm already using a different site, that I can use the Web.config to set the maxAllowedContentLength.
Mendy