繁体   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