簡體   English   中英

取消對網頁的導航,在 asp.net 網頁表單中獲取消息

[英]Navigation to the webpage was canceled getting message in asp.net web form

當我將 aspx 頁面下載為圖像格式然后在下載的圖像中收到以下錯誤消息時,但本地主機都認為只有當上傳到實時服務器然后下載的文件被下載時才能正常工作,但內部文件消息不是我的 aspx 數據顯示。

Navigation to the webpage was canceled

下面是我下載的帶有消息的圖像文件

在此處輸入圖片說明

我正在嘗試使用下面的 win 表單 WebBrowser 控件來截取網頁的屏幕,這是我的代碼

下面是將 URL 分配給文本框以供下載的代碼

  protected void Page_Load(object sender, EventArgs e)
{

   txtweburl.Text = "http://example.com/dicdownload.aspx?VisitedId=DIC_V00025";

 }

下面是使用線程生成屏幕的代碼

  protected void btnscreenshot_click(object sender, EventArgs e)
  {
    //  btnscreenshot.Visible = false;
    allpanels.Visible = true;
    Thread thread = new Thread(GenerateThumbnail);
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();

}

private void GenerateThumbnail()
{
    //  btnscreenshot.Visible = false;
    WebBrowser webrowse = new WebBrowser();
    webrowse.ScrollBarsEnabled = false;
    webrowse.AllowNavigation = true;
    string url = txtweburl.Text.Trim();
    webrowse.Navigate(url);
    webrowse.Width = 1400;
    webrowse.Height = 50000;

    webrowse.DocumentCompleted += webbrowse_DocumentCompleted;
    while (webrowse.ReadyState != WebBrowserReadyState.Complete)
    {
        System.Windows.Forms.Application.DoEvents();
    }
}

在下面的代碼中,我在下載刪除相同的文件后保存圖像文件

        private void webbrowse_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // btnscreenshot.Visible = false;
    string folderPath = Server.MapPath("~/ImageFiles/");

    WebBrowser webrowse = sender as WebBrowser;
    //Bitmap bitmap = new Bitmap(webrowse.Width, webrowse.Height);

    Bitmap bitmap = new Bitmap(webrowse.Width, webrowse.Height, PixelFormat.Format16bppRgb565);

    webrowse.DrawToBitmap(bitmap, webrowse.Bounds);


    string Systemimagedownloadpath = System.Configuration.ConfigurationManager.AppSettings["Systemimagedownloadpath"].ToString();
    string fullOutputPath = Systemimagedownloadpath + Request.QueryString["VisitedId"].ToString() + ".png";
    MemoryStream stream = new MemoryStream();
    bitmap.Save(fullOutputPath, System.Drawing.Imaging.ImageFormat.Jpeg);


    // You should put more appropriate MIME type as per your file time - perhaps based on extension
    Response.ContentType = "application/octate-stream";
    Response.AddHeader("content-disposition", "attachment;filename=" + Request.QueryString["VisitedId"].ToString() + ".png");
    // Start pushing file to user, IIS will do the streaming.
    Response.TransmitFile("~/ImageFiles/" + Request.QueryString["VisitedId"].ToString() + ".png");
    Response.Flush();//Won't get error with Flush() so use this Instead of End()
    var filePath = Server.MapPath("~/ImageFiles/" + Request.QueryString["VisitedId"].ToString() + ".png");
    if (File.Exists(filePath))
    {
        File.Delete(filePath);
    }


}

本地主機一切正常,但在實時下載帶有該消息的圖像時

我也檢查了以下解決方案

https://support.microsoft.com/en-in/help/967941/navigation-is-canceled-when-you-browse-to-web-pages-that-are-in-differ

IIS 配置:使用 SautinSoft.PdfVision 將頁面轉換為 PDF 時取消了對網頁的導航

在我的情況下,我們必須做三個設置然后我的下載部分工作得很好

1) SSL 證書

2) 我的網絡團隊將最低版本的 IIS 升級到 IIS10

3)設置IIS為64位版本

首先,嘗試重置 Internet Explorer 設置。

將站點添加到您的受信任站點。

  • 在 Internet Explorer 中,從頂部的菜單中選擇工具 > Internet 選項。
  • 將出現 Internet 選項窗口。 選擇安全選項卡。 然后單擊受信任的站點圖標。

在此處輸入圖片說明

  • 單擊站點按鈕。

在此處輸入圖片說明

  • 可信站點窗口將打開。 在網站框中鍵入站點的 URL,如圖所示。 單擊添加。 然后在http后面添加一個“s”(即使地址看起來像:”

https://trusted.website.com“)。 再次單擊添加。

確保您沒有選中需要服務器驗證 (https) 的框。 檢查兩次!

  • 單擊關閉按鈕。
  • 在仍選擇受信任站點的情況下,單擊“自定義級別”。

在此處輸入圖片說明

  • 安全設置 - 可信站點區域窗口將打開。 向下滾動,直到看到“顯示混合內容”。 選擇啟用。

在此處輸入圖片說明

  • 返回 Internet 選項窗口,單擊確定以保存更改。 再次嘗試該站點,看看它是否在這些設置下工作得更好。

唯一為我解決的問題是在托管 RDL 報告的服務器上禁用防火牆。

對於仍在嘗試解決此問題的任何人。 對我來說,它在我設置webBrowser.ScriptErrorsSuppressed = false;后起作用了webBrowser.ScriptErrorsSuppressed = false; 在我的代碼中。 試一試吧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM