Silverlight OOB WebBrowser异常
我有一个带有Web浏览器的oob应用程序.
I've got an oob app with a webbrowser on it.
Web浏览器源与我定义的URI进行了数据绑定.URI的路径指向我服务器上的网页,该网页显示其hardrive中的PDF文件.
The webbrowser source is databound with a URI defined by me. The URI has a path to a webpage from my server that displays a PDF file from its hardrive.
请注意,所有这些操作都是在本地网络上完成的.
Note that all this is done on a local network.
URI示例:uri =新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = somePDF.pdf");
URI example: uri = new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
页面代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
string myURL = Request.Url.ToString();
string[] ParamArray = Regex.Split(myURL, "pdf=");
string Params = ParamArray[ParamArray.Length - 1];
if (Params.Length > 0)
{
Filename = Regex.Replace(Params, @"//", @"\\"); ;
if (File.Exists(Filename))
{
Response.ContentType = "Application/pdf";
Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.
Response.End();
}
else
this.Title = "PDF Not Found";
}
}
protected void Page_Load(object sender, EventArgs e) { string myURL = Request.Url.ToString(); string[] ParamArray = Regex.Split(myURL, "pdf="); //If the URL has parameters, then get them. If not, return a blank string string Params = ParamArray[ParamArray.Length - 1]; if (Params.Length > 0) { //to the called (src) web page Filename = Regex.Replace(Params, @"//", @"\\"); ; if (File.Exists(Filename)) { Response.ContentType = "Application/pdf"; Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream. Response.End(); } else this.Title = "PDF Not Found"; } }
我第一次将WebBrowser源设置为显示PDF的所有内容.但是,当我第二次设置URI时,应用程序将引发异常:尝试撤消尚未注册的放置目标(HRESULT的异常:0x80040100).
The first time I set the WebBrowser source everything it displays the PDF. But when I set the URI one second time the app throws an exception: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100).
我已经做了一些测试,结果如下:
I've done a few tests and here are the results:
1º新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = somePDF.pdf");
1º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2º新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = someOtherPDF.pdf");->错误
2º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error
1º新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = somePDF.pdf");
1º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2º新的Uri(@"http://www.google.com");->错误
2º new Uri(@"http://www.google.com"); ->error
1º新的Uri(@"http://www.google.com");
1º new Uri(@"http://www.google.com");
2º新的Uri(@"http://www.microsoft.com");
2º new Uri(@"http://www.microsoft.com");
2º新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = somePDF.pdf");
2º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
3º新的Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf = someOtherPDF.pdf");->错误
3º new Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error
我也忘记了说,从浏览器(使用HTMLHost)运行应用程序时,页面显示良好.使用浏览器打开页面也可以正常工作.
I also forgot to say that when running the app from my browser (using a HTMLHost) the pages display just fine. Opening the pages using a browser will also work well.
我的aspx页面一定有问题.有什么想法吗?
It must be some problem with my aspx page. Any ideas?
佩德罗
我已经设法通过为每个页面创建一个新的浏览器来解决此问题.如果您知道更优雅的解决方案,请分享.
I've managed to resolve this by creating a new browser for each page. If you know of a more elegant solution please share.