Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request Entity Too Large for Self Hosted ASP.Net Web API

I have a large chunk of json that I need to post to a self hosted ASP.Net Web API Service.

I get the "Status Code:413 Request Entity Too Large" message.

Tried to put the following in the app.config of the webapi service project.

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off"/>
    <httpRuntime
        maxRequestLength="2147483647"
        executionTimeout="300" />
</system.web>

This didn't help.

I am thinking about the following two options.

  1. Decompress the data in javascript possibly using LZW compression library and decode it on the webapi side after receiving.
  2. Find a way to allow the webapi infrastructure to allow large chunk of data

I prefer the 2nd option, but have not yet found how to make it happen.

Any pointers?

like image 202
Vin Avatar asked Oct 18 '13 15:10

Vin


1 Answers

I was getting the same problem and was able to make the change in code.

var config = new HttpSelfHostConfiguration(host);
config.MaxReceivedMessageSize = 2147483647; // use config for this value
/*
other setup for the config
*/
using (var server = new HttpSelfHostServer(config))
{
    server.OpenAsync().Wait();
    Console.WriteLine("Insight.Web");
    Console.ReadLine();
}
like image 80
Brandon Avatar answered Sep 26 '22 12:09

Brandon