简体   繁体   中英

Read first bytes of body when "Maximum request length exceeded"

I have a ASP.NET WebAPI application and some of the request exceed the maximum lenght. That's fine, I know I can increase the limit either in IIS or web.config , but that's not my point.

When I read the contents of the request using one of the Request.Content.Read methods all of them return a Maximum request length exceeded exception.

I would like to retrieve the first characters of the body though, for logging purposes.

Is it still possible to read just the first characters of the body? Or is the whole content impossible to retrieve?

you must catch the exception on global.asax file, then you will have the request data.

see these 2 links:

Catching "Maximum request length exceeded" http://geekswithblogs.net/sglima/archive/2011/09/20/how-to-handle-maximum-request-length-exceeded-exception.aspx

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