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.
https ://trusted.website.com“). Click Add again.
Be certain that you do NOT check the box for Require server verification (https). Check it twice!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With