开发者

Using HtmlPage.Window.Navigate in Silverlight Windows opens then immediately closes in IE

Here is the code that i'm using:

System.Windows.Browser.HtmlPopupWindowOptions pop = new System.Windows.Browser.HtmlPopupWindowOptions();
pop.Directories = false;
pop.Menubar = false;
pop.Status = false;
pop.Toolbar = false;
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(@"http://" + App.Host + App.VirtualDirectory+ "/Print.aspx?ID=" + ID, UriKind.Absolute), "_blank", "location=no, toolbar=no, status=no");

What happens is in production only (Works locally and in a testing environment) the window displays and then immediately closes. Again this works fine locally in my development environment and then on an internal testing environment.

The page being called creates a dynamic PDF to be displayed to the screen. Here is the code 开发者_运维问答that modifies the response object:

context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.AddHeader("Content-Disposition", "attachment;filename=print.pdf");

Then writes the actual PDF object to the output stream.

If I open the URL in a new Tab in IE I can view the document as intended, it's only through the print button inside Silverlight and only in IE. I have tried this in Chrome and it works fine, haven't tested Firefox.

There is no pop-up blocker involved, the window shows up then disappears. I have checked security settings and added the domain to my list of trusted sites. Looking for any other suggestions.


I'm answering my own question because I've found a suitable workaround.

I replaced the line

context.Response.AddHeader("Content-Disposition", "attachment;filename=print.pdf");

With

context.Response.ContentType = "application/pdf";

So instead of presenting the user with an Open/Save dialog it opens directly in the browser if they have a pre-defined PDF viewer. They can then print or save the file from Internet Explorer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜