Custom Handler Doesn't Like Spaces On Firefox
<p>I have a custom handler implementing IHttpHandler. The custom handler allows us to produce a dynamic URL for people to download files.</p>

<p>The code looks like this,</p>

<pre><code>public void ProcessRequest(HttpContext context)
{
    context.Response.AddHeader("Content-Disposition", "attachment;filename=" + attachment.FileName);
    context.Response.AddHeader("Content-Length", attachment.Fileblob.Length.ToString());
    context.Response.ContentType = GetMimeType(attachment.FileName);
    context.Response.OutputStream.Write(attachment.Fileblob, 0, attachment.Fileblob.Length);
}
</code></pre>

<p>The problem is with attachment.Filename. If the filename happens to have a space like this,</p>

<p>filename - 1.bmp</p>

<p>Then on internet explorer it works fine, but on firefox the file download dialog truncates it to be this,</p>

<p>filename</p>

<p>No extension or anything. I also tried this,</p>

<p>attachment.FileName.Replace(" ", "%20")</p>

<p>Which works in IE again, but in firefox it results in the filename being set to this in the download dialog,</p>

<p>filename%20-%201.bmp</p>

<p>I also tried this,</p>

<p>HttpUtility.UrlEncode(attachment.FileName)</p>

<p>In both firefox and IE that results in this,</p>

<p>filename+-+1.bmp</p>

<p>Any ideas?</p>
