user2433166
user2433166

Reputation: 11

Mvc apicontroller , how can i set unlimited length for maxJsonLength when i receive the request

I am new to mvc and ran into an issue wile creating a controller api where it will be able to accept files in the httpRequest. It works fine for small files, but when the size of the file exceeds 4MB, it fails with "Internal server error", the request does not even hit my controller api.

I did see some posts where it has mentioned to use JavascripSerializer in a controller. (Can I set an unlimited length for maxJsonLength in web.config? 9)

But i am not sure how to use this when accepting a request with larger files.

Any help on this is appreciated.

Upvotes: 0

Views: 1348

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

But i am not sure how to use this when accepting a request with larger files.

In your web.config you could increase the maximum size of the request:

<system.web>
    <!-- Set the maximum request size to 1GB (the value is in KB here) -->
    <httpRuntime maxRequestLength="1048576" />
    ...
</system.web>

and if you are running in IIS 7 integrated pipeline mode you also need to set the <requestLimits> to the same value:

<system.webServer>
    <security>
        <requestFiltering>
           <!-- Set the maximum request size to 1GB (the value is in Bytes here) -->
            <requestLimits maxAllowedContentLength="1073741824" />
        </requestFiltering>
    </security>
</system.webServer>

Upvotes: 1

Related Questions