Increase maxRequestLength for MVC Controller Action

Is it possible to increase the maxRequestLength of an ASP.NET request for an MVC controller action?

I have an MVC controller that accepts a file, and it can be very large. I increased maxRequestLength in web.config, but this is a security issue, and the best solution for me would be to increase the request length for the Upload method only. Is it possible?

I tried

<location path="UploadFile">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
      <httpRuntime maxRequestLength="2097151"/>
    </system.web>
  </location>

But it did not help

Thank.

+3
source share
1 answer

Is it possible to increase the maxRequestLength of an ASP.NET request for an MVC controller action?

AFAIK, no. But you can use a common HTTP handler instead of a controller action, and then your <location path="UploadFile"> will work. For example, your handler might be placed in ~/UploadFile/upload.ashx.

+4
source

All Articles