简体   繁体   中英

ASP.NET Web API request does not reach controller action

I have trouble posting 'large' objects to my web api using the HttpClient's PostAsJsonAsync method. The objects contain a base64 encoded image file.

After a period which seems like the client's timeout setting, the exception

'A task was canceled.'

is thrown by the HttpClient . The timeout is already set very high (10 minutes). This only happens with files larger than ~2 MB. Anything smaller works fine. I know that the request does not even hit the first line of code in the controller method because the first line is a logging line and the log is empty. There are no exceptions in the server event viewer.

It is hard to pin down the issue because the controller works fine when I deploy the web api on my local IIS. But when I deploy it on my Azure VM, it only work for small files. The web.config files are identical.

maxRequestLength is already set high enough.

<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />

Instead of IIS hosting in an Azure VM, i've just tried to deploy the API as an app service. The exact same thing happens there.

You can also try setting this limit:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1073741824" />
       </requestFiltering>
    </security>
</system.webServer>

Note that contrary to the maxRequestLength parameter, this value is in bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM