2

I was wondering whether it is possible to define web.config settings specifically for certain URLs.

For example: Let's say I have an MVC4 web site with a bunch of controllers and actions, one of which allows uploading a large file (max. 50MB). By default, the maxRequestLength is 4MB. In web.config one would then add the following rule:

<httpRuntime maxRequestLength="51200" />

However, this means that the request length is now 50MB for every action on the website. Is it possible to make custom settings for specific URLs?

Knelis
  • 6,782
  • 2
  • 34
  • 54

3 Answers3

1

Simply use location for setting different values. See this answer for instance How to set different Timeouts for different URLs in ASP.NET It's for setting a timeout, but it's the same...

Community
  • 1
  • 1
walther
  • 13,466
  • 5
  • 41
  • 67
0

You can try to set it in controller itself using MaxRequestLength property, but not sure if it is possible to set it for specific action. Approach with location setting will not work, because MVC uses routing.

Alex
  • 1,657
  • 1
  • 12
  • 6
0

One solution can be to create a new folder and place your controllers that you need and create a web.config for that folder. And i think this is not a good approach :)

MRB
  • 3,752
  • 4
  • 30
  • 44