[英]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);
}
}
本地主机一切正常,但在实时下载带有该消息的图像时
我也检查了以下解决方案
在我的情况下,我们必须做三个设置然后我的下载部分工作得很好
1) SSL 证书
2) 我的网络团队将最低版本的 IIS 升级到 IIS10
3)设置IIS为64位版本
首先,尝试重置 Internet Explorer 设置。
将站点添加到您的受信任站点。
https://trusted.website.com“)。 再次单击添加。
确保您没有选中需要服务器验证 (https) 的框。 检查两次!
唯一为我解决的问题是在托管 RDL 报告的服务器上禁用防火墙。
对于仍在尝试解决此问题的任何人。 对我来说,它在我设置webBrowser.ScriptErrorsSuppressed = false;
后起作用了webBrowser.ScriptErrorsSuppressed = false;
在我的代码中。 试一试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.