Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net MVC sending file without content size. Browser doesnt prompt save dialog until transfer is finished
    primarykey
    data
    text
    <p>I am writing on the fly file zipper.</p> <p>I cant calculate correct file size of a future archive, so can specify Content-Length.</p> <p>This code did not prompt save file dialog until both Thread.Sleep() methods returned.</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult Download() { return new DelayedUnsepcifiedLengthZipArchiveResult(); } } public class DelayedUnsepcifiedLengthZipArchiveResult : ActionResult { public override void ExecuteResult(ControllerContext context) { context.HttpContext.Response.ContentType = "application/zip"; context.HttpContext.Response.CacheControl = "private"; context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.HttpContext.Response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}\"", "test.zip")); context.HttpContext.Response.Flush(); Thread.Sleep(10000); context.HttpContext.Response.Write("hello world"); context.HttpContext.Response.Flush(); Thread.Sleep(10000); context.HttpContext.Response.Write("hello world2"); context.HttpContext.Response.Flush(); context.HttpContext.Response.End(); } } </code></pre> <p>In Chrome and IE 10 I got save dialog after 20 secs...</p> <p>Is it a way to fix it?</p> <p>Update:</p> <p>Fidler goes crazy. Not sure, maybe Fidler adds Conent-Length automatically. This is raw data I getting from fidler</p> <p>At the start</p> <pre><code>HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Transfer-Encoding: chunked Content-Type: application/zip Expires: -1 Server: Microsoft-IIS/8.0 X-AspNetMvc-Version: 4.0 content-disposition: attachment; filename="test.zip" X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?RDpcV29ya1xBY2FkZW15XEhpZ2hMb2FkQ2hhblxEb3dubG9hZGVyXGhvbWVcZG93bmxvYWQ=?= X-Powered-By: ASP.NET Date: Mon, 04 Mar 2013 13:39:24 GMT </code></pre> <p>After download finished:</p> <pre><code>HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Type: application/zip Expires: -1 Server: Microsoft-IIS/8.0 X-AspNetMvc-Version: 4.0 content-disposition: attachment; filename="test.zip" X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?RDpcV29ya1xBY2FkZW15XEhpZ2hMb2FkQ2hhblxEb3dubG9hZGVyXGhvbWVcZG93bmxvYWQ=?= X-Powered-By: ASP.NET Date: Mon, 04 Mar 2013 13:39:24 GMT Content-Length: 23 hello worldhello world2 </code></pre> <p>UPDATE 2:</p> <pre><code>fiddler coused such veird behaviour, problem closed. Turn off your debug proxies bros... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload