简体   繁体   English

取消对网页的导航,在 asp.net 网页表单中获取消息

[英]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.当我将 aspx 页面下载为图像格式然后在下载的图像中收到以下错误消息时,但本地主机都认为只有当上传到实时服务器然后下载的文件被下载时才能正常工作,但内部文件消息不是我的 aspx 数据显示。

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我正在尝试使用下面的 win 表单 WebBrowser 控件来截取网页的屏幕,这是我的代码

Below is code assigning URL to textbox for downloading下面是将 URL 分配给文本框以供下载的代码

  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 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 IIS 配置:使用 SautinSoft.PdfVision 将页面转换为 PDF 时取消了对网页的导航

At my case we have to do three setting then my download part working perfectly fine在我的情况下,我们必须做三个设置然后我的下载部分工作得很好

1) SSL Certificates 1) SSL 证书

2) My Network Team Upgrade lowest version IIS to IIS10 2) 我的网络团队将最低版本的 IIS 升级到 IIS10

3) Set the IIS to 64 bit version 3)设置IIS为64位版本

First, try to reset Internet Explorer settings.首先,尝试重置 Internet Explorer 设置。

Add a site to your trusted sites.将站点添加到您的受信任站点。

  • In Internet Explorer, select Tools > Internet Options from the menu at the top.在 Internet Explorer 中,从顶部的菜单中选择工具 > Internet 选项。
  • The Internet Options window will appear.将出现 Internet 选项窗口。 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.在网站框中键入站点的 URL,如图所示。 Click Add.单击添加。 Then add an ” s” after the http (ie make the address look like: ”然后在http后面添加一个“s”(即使地址看起来像:”

https ://trusted.website.com“). https://trusted.website.com“)。 Click Add again.再次单击添加。

Be certain that you do NOT check the box for Require server verification (https).确保您没有选中需要服务器验证 (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.返回 Internet 选项窗口,单击确定以保存更改。 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;对我来说,它在我设置webBrowser.ScriptErrorsSuppressed = false;后起作用了webBrowser.ScriptErrorsSuppressed = false; in my code.在我的代码中。 Do give it a try.试一试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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