Error reading MIME multipart body part. ---> System.Web.HttpException: The client disconnected when file uploaded in web application - client

There is a strange behavior, user is unable to upload a file in web application getting below
'Error reading MIME multipart body part. System.IO.IOException: Error reading MIME multipart body part. ---> System.Web.HttpException: The client disconnected.'
but the same file I am able to upload without any errors.
We tried below options by going through the articles and similar error posts but no luck.
I tried switching out the Task.Factory code:
var task = Task.Factory .StartNew(() => parts = Request.Content.ReadAsMultipartAsync().Result.Contents, CancellationToken.None, TaskCreationOptions.LongRunning, // guarantees separate thread TaskScheduler.Default);
with below
var task = Task.Run(async () => await Request.Content.ReadAsMultipartAsync()); parts = task.Result.Contents;
Increased max request limits in web.config like maxRequestLength="2147483647", maxAllowedContentLength="157286400".
I see errors like below in logs
Error reading MIME multipart body part. System.IO.IOException: Error reading MIME multipart body part. ---> System.Web.HttpException: The client disconnected. at System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult) at System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
I am unable to reproduce this error in any of my environments, not sure what is causing in user environment. Any suggestions?

Related

Windows phone app - live tile https issue

Recently I updated the scheme from http to https in my window phone app. So far network request works fine.
However, the live tile is not working anymore.
Then I tried to debug and found that:
System.ArgumentException occurred at Microsoft.Phone.TaskModel.Interop.ApplicationHost.GetFileSystemPath(String uri)
Also:
System.Reflection.TargetInvocationException occurred Message:
A first chance exception of type
'System.Reflection.TargetInvocationException'
occurred in mscorlib.ni.dll
Additional information: Exception has been thrown by the target of an
invocation.
Finally:
at Microsoft.Phone.TaskModel.Interop.ApplicationHost.GetFileSystemPath(String uri)
at Microsoft.Phone.Shell.ShellTileData.GetLocalFilePath(Uri imageUri)
at Microsoft.Phone.Shell.UriToLocalStoreConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at Microsoft.Phone.Shell.ShellTileData.SerializeToToken(IPMTileInfo token)
at Microsoft.Phone.Shell.ShellTile.Update(ShellTileData data)
at AlarmScheduledTaskAgent.ScheduledAgentSettings.updateLiveTileUI()
I know the issue comes from the URI image for liveTile because if I change back to http liveTile is loading the image correctly. Also I tried to use another http image it doesn't crash. But if I use another https image online it crashes.
Although I didn't find anything indicating liveTile doesn't support https, anyone knows how to fix the issue? Thanks!

Error while running VS Webtest

While running a simple visual studio webtest (ensure that my SERVER responds appropriately to a GET request), I get an appropriate response (i.e. the value for the key I'm passing as a parameter). However, the test fails with the following error:
"Request failed: Value cannot be null.
Parameter name: uriString"
and the only available stacktrace reading:
System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
at System.Uri..ctor(String uriString, UriKind uriKind)
at Microsoft.VisualStudio.TestTools.WebStress.WebTestInstrumentedTransaction.ProcessCompletedRequest(Boolean completedSynchronously)"
I don't use a uriString variable anywhere in my code.
Any suggestions on how to fix this?
Figured it out, and it wasn't an issue with the test. My setup was responding with a 302, which needs a redirection header that was not being populated (I intended to use a 200, but confused HTTPStatusCode Found with OK), which caused the above

HandlerExceptionResolver, MaxUploadSizeExceededException - Upload continues and error not returned immediately

I am using Spring 3.1.1. I have a file upload feature and have implemented HandlerExceptionResolver to handle file size limit. I have configured the size in spring mvc xml with "maxUploadSize" attribute. My application uses spring security with open id.
I am using the code below in resolveException() of that upload controller. RestResponse is a pojo with error message and status
ModelAndView mav = new ModelAndView();
mav.setView(new MappingJacksonJsonView());
RestResponse fail_response = new RestResponse();
fail_response.setMessage("Max upload limit failure.");
fail_response.setStatus("FAIL");
mav.addObject("restResponse", fail_response);
return mav;
I can see from the logs that, the resolveException() is invoked, however the json response is not shown in the rest api client/browser. I can see the exception in the log (Maximum upload size of 10485760 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (30611515) exceeds the configured maximum (10485760)) immediately after the upload, but the upload still continues and after a while the json error message (available above) is shown in the browser.
I did check for this problem in stackoverflow and other portals and could not find why it is not shown or response is returned to the UI.
See this issue and this SO. If still not clear, refer to this link
and search for maxFileSize and maxRequestSize. Add same settings in your application.yml

Error in Dropbox file download using WebClient

I am working on downloading a text file hosted in dropbox. But i am getting a 400 Error code in the Completed function. I find the problem is with the dropbox hosted files only. I could download other sample text files hosted such as "http://wordpress.org/plugins/about/readme.txt".
Below is the code snippet i am using for downloading a text file from dropbox.
void downloadFile()
{
WebClient webClient = new WebClient();
NetworkCredential Credentials = new NetworkCredential(<username>, <password>, "<domain>);
webClient.Proxy = WebRequest.GetSystemWebProxy();
webClient.Proxy.Credentials = Credentials;
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadFileAsync(<downloadfileurl>, #"C:\test.txt");
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show("Successfully downloaded");
}
else
{
MessageBox.Show(e.Error.ToString());
}
}
The following is the error am getting :
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
Any support to tweak this problem will be highly appreciated.
Note : I have also tried using the WebRequest(POST), but same error there also.
Thanks in advance.
It looks like you're trying to use some sort of username/password authentication to download the file? Dropbox doesn't support any such thing.
You didn't share the URL you're trying to download. If it's a share link (a link created by a user who shared a file), it should just work with no authentication. If it's a file that hasn't been shared, you'll need to access it via the Dropbox API. See https://www.dropbox.com/developers to start learning about the Dropbox API.

jqgrid server exception error messages

Is there a way to show custom exception messages sent from the server in my jqGrid???? One of my function does a throws clause and throws some exception. I need to disoplay the error message relative to this thrown exception... Is there a way to do that in jqGrid???
You don't spectify in what jqGrid operation the exception could be throwen. There are different event handler which you can use to receive the text of the error message from the exception and decode it.
For example loadError(xhr,st,err) can be used to display the error messege which appears on the server during the loading of the jqGrid. I mean here the errors returned by the server on the ajax requests.
Additionally errorTextFormat(data) can be used to decode errors come up from the server during the ajax requests of the form editing. or errorfunc(rowid,res,stat) for the inline editing and errorCell(serverresponse,status) for cell editing.
So you can use the corresponding event handler functions in different places to decode the text of the exception message.

Resources