开发者

ParserError when using AppendHeader

I'm calling a method that I expect to let a user download a file from my server:

string path = MapPath(filePath);
     string name = Path.GetFileName(path);
     string ext = Path.GetExtension(path);
     string type = "";
     // set known types based on file extension  
     if (ext != null) {
        switch (ext.ToLower()) {
           case ".pdf":
              type = "Application/pdf";
              break;
        }
     }
     Response.AppendHeader("content-disposition",
         "attachment; filename=" + name);

     if (type != "") {
        Response.ContentType = type;
     }
     Response.WriteFile(path);
     Response.End(); 

I get the following error:

Foutdetails webpagina

Gebruikersagent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Tijdstempel: Mon, 17 Oct 2011 14:09:42 UTC

Bericht: Sys.WebForms.PageRequestManagerParserErrorException: Het bericht dat is ontvangen van de server, is niet geparseerd. Vaak wordt dit probleem veroorzaakt door het feit dat het antwoord is aangepast met aanroepen naar Response.Write(), antwoordfilters, HttpModules, of door het feit dat servertracering is ingeschakeld. Details: Er is een fout opgetreden tijdens het parseren dichtbij %PDF-1.6 %�� 1246 0 . Regel: 4723 Teken: 21 Code: 0 URI: http://localhost:8080/ScriptResource.axd?d=pIR8OXvZoRojyW4g1LrIxQJ_PBSxowcac32J1wj6iuXDcoXm42o2_-RXqxdcfui11rd_ENAmsJBy6ZuWa6y59BIFz75plfDb9hceJY8IfLYyZk116lcE26DPuxB8-NB46RAswwOW4RN2EGnFK-0MTXrgj2R-IGGgc开发者_运维问答AS9lqbJpejfFHbU0&t=ffffffffdf4bca0c

Any suggestions on how to solve this type of errors?


If you're doing this via AJAX through an UpdatePanel, you need to add the button as a PostBackTrigger. You can also add the button as a postback control in the code-behind like this:

ScriptManager.GetCurrent(Page).RegisterPostBackControl(Button1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜