我有一个带有网页浏览器的oob应用程序。
webbrowser源是用我定义的URI进行数据库的。URI有一个从我的服务器到一个网页的路径,该页面从它的hardrive显示一个PDF文件。
请注意,所有这些都是在本地网络上完成的。
URI示例: uri =新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时,应用程序抛出一个异常:试图撤销未注册的drop目标( HRESULT: 0x80040100中的例外)。
我做了一些测试,结果如下:
1.新Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2新Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf");->error
1.新Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2新Uri(@"http://www.google.com");->error
1.新Uri(@"http://www.google.com");
2.新Uri(@"http://www.microsoft.com");
2.新Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
3.新Uri(@"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf");->error
我还忘了说,在我的浏览器(使用HTMLHost)运行应用程序时,页面显示得很好。使用浏览器打开页面也会很好。
这一定是我的aspx页面出了问题。有什么想法吗?
佩德罗
发布于 2010-10-11 09:38:27
我已经通过为每个页面创建一个新浏览器来解决这个问题。如果你知道一个更优雅的解决方案,请分享。
发布于 2010-12-13 23:17:10
我不确定我是否正确地理解了这个问题/问题,但可能会加载页面异步,然后分配给webbrowser?如果我不在这里,请原谅我。
public void ShowLink(string linkUrl)
{
if (App.Current.IsRunningOutOfBrowser)
{
var pageRequest = new WebClient();
pageRequest.DownloadStringCompleted += pageRequest_DownloadStringCompleted;
pageRequest.DownloadStringAsync(new Uri(linkUrl, UriKind.Absolute));
}
}
void pageRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
webBrowserLink.NavigateToString(e.Result.ToString());
}https://stackoverflow.com/questions/3904341
复制相似问题