Fitzchak Yitzchaki
Fitzchak Yitzchaki

Reputation: 9163

Set MaxAllowedContentLength/maxRequestLength value per action

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?

Upvotes: 8

Views: 2368

Answers (2)

Fitzchak Yitzchaki
Fitzchak Yitzchaki

Reputation: 9163

I didn't find a way to achieve that, and I don't think that there is. Probably the best thing to do is to use a different IIS Website for the file download actions, with custom web.config.

Upvotes: 1

Carter Medlin
Carter Medlin

Reputation: 12495

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.

Upvotes: 0

Related Questions