2014-11-24 81 views
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是空的?

+0

请查看这篇文章[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

+0

@ bastos.sergio感谢您的反馈意见。这个问题是问如何增加大小。我认为没有必要比我已经做的更多地扩大规模。我只是想看看是否有错误发生,抛出一个413而不是404,但我不知道我是如何(如果有的话),可以发现,它真的发生了。 – Alexander 2014-11-24 16:38:12

回答

1

根据这一blog,状态代码404.13在IIS 7中引入,以取代HTTP状态代码413

,因为这是由设计完成的,我建议你保持响应,是,并在你的代码中尝试确定404错误实际上是否是404.13错误。