简体   繁体   中英

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

When i am download aspx page to image format then getting below error message in downloaded image, but local host every think working fine only when upload into live server then downloaded file is download but inside file message is coming not my aspx data showing.

Navigation to the webpage was canceled

below is my downloaded image file with message

在此处输入图片说明

I am tring to take screen short of the web page using win form WebBrowser control below is my code

Below is code assigning URL to textbox for downloading

  protected void Page_Load(object sender, EventArgs e)
{

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

 }

Below is code for generate screeen using thread

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

In below code I am saving the image file after download deleting the same file

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


}

Local host everything working fine but when it is in live downloading the image with that message

I have check with below solution also

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

IIS configuration: Navigation to the webpage was canceled when converting page to PDF using SautinSoft.PdfVision

At my case we have to do three setting then my download part working perfectly fine

1) SSL Certificates

2) My Network Team Upgrade lowest version IIS to IIS10

3) Set the IIS to 64 bit version

First, try to reset Internet Explorer settings.

Add a site to your trusted sites.

  • In Internet Explorer, select Tools > Internet Options from the menu at the top.
  • The Internet Options window will appear. Select the Security tab. Then click on the Trusted sites icon.

在此处输入图片说明

  • Click the Sites button.

在此处输入图片说明

  • The Trusted sites window will open. Type the URL of the site in the website box as shown. Click Add. Then add an ” s” after the http (ie make the address look like: ”

https ://trusted.website.com“). Click Add again.

Be certain that you do NOT check the box for Require server verification (https). Check it twice!

  • Click the Close button.
  • With Trusted sites still selected, click ” Custom Level“.

在此处输入图片说明

  • The Security Settings – Trusted Sites Zone window will open. Scroll down until you see ” Display mixed content“. Select Enable.

在此处输入图片说明

  • Back on the Internet Options window, click OK to save the changes. Try the site again to see if it works better with these settings.

唯一为我解决的问题是在托管 RDL 报告的服务器上禁用防火墙。

For anyone who is still trying to figure this out. For me it worked after I set webBrowser.ScriptErrorsSuppressed = false; in my code. Do give it a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM