取消导航到该网页,以asp.net Web形式获取消息

moh*_*han 7 c# asp.net iis networking webforms

当我将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";

 }
Run Code Online (Sandbox Code Playgroud)

下面是使用线程生成屏幕的代码

  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();
    }
}
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,我下载后删除相同的文件,然后保存图像文件

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


}
Run Code Online (Sandbox Code Playgroud)

本地主机一切正常,但是当它正在实时下载带有该消息的映像时

我也检查以下解决方案

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

IIS配置:使用SautinSoft.PdfVision将页面转换为PDF时,取消了对网页的导航

moh*_*han 5

就我而言,我们必须进行三个设置,然后我的下载部分就可以正常工作

1) SSL 证书

2) 我的网络团队将最低版本的IIS升级到IIS10

3)将IIS设置为64位版本