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