Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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

like image 266
mohd mazhar khan Avatar asked Aug 22 '19 05:08

mohd mazhar khan


2 Answers

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

like image 104
mohd mazhar khan Avatar answered Nov 13 '22 02:11

mohd mazhar khan


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.

enter image description here

  • Click the Sites button.

enter image description here

  • 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 (i.e. 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“.

enter image description here

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

enter image description here

  • 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.
like image 27
Jalpa Panchal Avatar answered Nov 13 '22 01:11

Jalpa Panchal