[英]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.