Handler serves dynamic mp3 as .xhtml files in Safari - works in FF / IE

Last post 06-27-2009 4:51 PM by headchem. 0 replies.

Sort Posts:

  • Handler serves dynamic mp3 as .xhtml files in Safari - works in FF / IE

    06-27-2009, 4:51 PM
    • Member
      20 point Member
    • headchem
    • Member since 02-08-2007, 11:24 AM
    • Elon, NC
    • Posts 40

    Here is the page that I'm having trouble with: http://headchemists.com/Song.aspx?id=5

    When you click on either "Original Vocal Mix" or "Instrumental Mix" a mp3 file should download.  It works correctly in FF / IE, but Safari downloads the mp3 as a .xhtml file.  Any help greatly appreciated!  Below is my handler code:


    private int itemId = -1;
    
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ClearHeaders();
    
        itemId = int.TryParse(context.Request.QueryString["id"], out itemId) == true ? itemId : -1;
    
        GetPackages get = new GetPackages();
        Item item = get.GetItem(itemId);
    
        Package package = get.GetPackage(item.PackageId);
    
        context.Response.AppendHeader("Content-Length", item.BinaryFile.Length.ToString());
        context.Response.ContentType = "audio/mpeg";
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + package.Title.Replace(" ", "_") + "_(" + item.Title.Replace(" ", "_") + ")" + ".mp3\"");
    
        context.Response.OutputStream.Write(item.BinaryFile, 0, item.BinaryFile.Length);
        context.Response.End();
    }


    Filed under: , ,
Page 1 of 1 (1 items)