0
我通过POST发送文件给我ApiController。我可以找到最大张贴尺寸是否过大?
如果该文件是低于2 MB,一切就像一个魅力。 如果文件比较大,我得到一个错误404
这是在我的控制器(旧)函数声明:
[HttpPost]
public HttpResponseMessage FileUpload(HttpRequestMessage req, string entryId = "", string owner = "", int debug = 0)
{
返回,如果实体过大,这样的:
Remote Address:172.17.41.12:443
Request URL:https://webdevserver/myapp/api/Debug/FileUpload
Request Method:POST
Status Code:404 Not Found
,或者如果它是大小限制内,这样的:
Remote Address:172.17.41.12:443
Request URL:https://webdevserver/myapp/api/Debug/FileUpload
Request Method:POST
Status Code:200 OK
所以我想发送一个有用的错误消息 - 哪个错误404绝对不是! - 并在HTTP状态代码413,这IIS不会自动发送迷迷糊糊:(所以我改变了我的代码:
[HttpPost]
public HttpResponseMessage FileUpload(HttpRequestMessage req=null, string entryId = "", string owner = "", int debug = 0)
{
if(req==null) {
// POST was not handed over to my function by IIS
// now is it possible to check whether file was empty or too large!? Because
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
// should only be sent if POST content was really too large!
所以,我怎么能检查POST数据的大小是否过大或POST是空的?
请查看这篇文章[WebRequest的 - 失败 - 与-A-404-13]([http://stackoverflow.com/questions/9310926/iis7-webrequest-failing-with-a-404-13-when-该尺寸的最请求-PARAMS-EXCE) – 2014-11-24 16:35:19
@ bastos.sergio感谢您的反馈意见。这个问题是问如何增加大小。我认为没有必要比我已经做的更多地扩大规模。我只是想看看是否有错误发生,抛出一个413而不是404,但我不知道我是如何(如果有的话),可以发现,它真的发生了。 – Alexander 2014-11-24 16:38:12