gpt4 book ai didi

c# - 在 asp.net web 表单中获取消息的网页导航被取消

转载 作者:太空狗 更新时间:2023-10-29 20:19:12 25 4
gpt4 key购买 nike

当我将 aspx 页面下载为图像格式时,下载图像中出现以下错误消息,但本地主机每个人都认为只有在上传到实时服务器时才能正常工作,然后下载下载的文件,但内部文件消息不是我的 aspx 数据显示.

网页导航已取消

下面是我下载的带有消息的图片文件

enter image description here

我正在尝试使用 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 configuration: Navigation to the webpage was canceled when converting page to PDF using SautinSoft.PdfVision

最佳答案

在我的情况下,我们必须进行三个设置,然后我的下载部分才能正常工作

1) SSL证书

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

3) 设置IIS为64位版本

关于c# - 在 asp.net web 表单中获取消息的网页导航被取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57602584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com