0

I am writing a controller to copy FileStream content and I am getting error The Client Disconnected at below line,

await Request.Content.CopyToAsync(fs);

What could be the reason?

public async Task<IHttpActionResult> Post()
    {
        try
        {
            string path = @"C:\Test";

            using (FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write))
            {
                await Request.Content.CopyToAsync(fs);
            }

            return Ok<bool>(true);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
user584018
  • 10,186
  • 15
  • 74
  • 160
  • 1
    Your way of re-throwing the Exception clears the stacktrace. Wich is about 95% of the Exceptions information. Of course the whole idea of catching Exception just to rethrow it seems odd too. There is two articles on exception handling that I found very helpfull: http://blogs.msdn.com/b/ericlippert/archive/2008/09/10/vexing-exceptions.aspx http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET The exception you have sounds first and foremost to be a exogenous Exception. However as you asked, it might happen during testing. Wich would make it a bonehaded one. – Christopher Jan 08 '18 at 10:50
  • Is there any way to resolve it? – user584018 Jan 08 '18 at 10:52
  • 1
    @user584018 try to omit the exception handler, and check – Ferus7 Jan 08 '18 at 10:57

0 Answers0