2010-10-11 9 views
0

J'ai une application oob avec un webbrowser dessus.Silverlight OOB WebBrowser Exception

La source webbrowser est databound avec un URI défini par moi. L'URI a un chemin vers une page Web de mon serveur qui affiche un fichier PDF à partir de son disque dur.

Notez que tout ceci est fait sur un réseau local.

Exemple d'URI: uri = new Uri (@ "http: //ServerName/ProjectName/PDFViewer.aspx? Pdf = somePDF.pdf");

page code-behind:

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";   }  } 

La première fois que je mets le tout source WebBrowser il affiche le PDF. Mais quand je place l'URI une deuxième fois l'application jette une exception: Essayer de révoquer une cible de baisse qui n'a pas été enregistrée (Exception de HRESULT: 0x80040100).

Je l'ai fait quelques tests et voici les résultats:

1º nouvelle Uri (@ "http: //ServerName/ProjectName/PDFViewer.aspx pdf = somePDF.pdf");

2º nouveau Uri (@ "http: //ServerName/ProjectName/PDFViewer.aspx? Pdf = someOtherPDF.pdf"); -> erreur


1º nouveau Uri (@ "? Http: //ServerName/ProjectName/PDFViewer.aspx pdf = somePDF.pdf");

2º nouveau Uri (@ "http://www.google.com"); -> erreur


1º nouvelle Uri (@ "http://www.google.com");

2º nouveau Uri (@ "http://www.microsoft.com");

2º nouveau Uri (@ "http: //ServerName/ProjectName/PDFViewer.aspx? Pdf = somePDF.pdf");

3º nouveau Uri (@ "http: //ServerName/ProjectName/PDFViewer.aspx? Pdf = someOtherPDF.pdf"); -> erreur


J'ai aussi oublié de dire que lors de l'exécution de l'application de mon navigateur (en utilisant un HTMLHost) les pages affichent très bien. Ouvrir les pages en utilisant un navigateur fonctionnera également bien.

Il doit y avoir un problème avec ma page aspx. Des idées?

Pedro

+0

Même erreur, dans le navigateur SL5. Fonctionne bien avec SL localement. Sur le vrai serveur Web obtenant cette erreur chaque fois que j'essaye de re-Naviguer le webbrowser. – felickz

Répondre

0

J'ai réussi à résoudre ce problème en créant un nouveau navigateur pour chaque page. Si vous connaissez une solution plus élégante, partagez-la.

0

Je ne sais pas si je suis correctement la question/problème, mais peut-être charger les pages asynchrones et ensuite assigner à webbrowser? Pardonnez-moi si je suis hors-base ici.

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()); 
     } 
Questions connexes