Request Entity Too Large for Self Hosted ASP.Net Web API在Selfhost的api后台怎么解决Request Entity Too Large问题

如果用的IIS承载api,可以在web.config中添加配置来解决

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

但在Selfhost中App.config没办法添加此配置

正常的添加方法应该在添加selfhost绑定配置项时添加

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();
}

 

posted on 2016-04-13 10:57  Mack.Meng  阅读(674)  评论(0编辑  收藏  举报