Error: Capture Screenshot not working after Publish in IIS

Last Reply on Mar 17, 2017 04:29 AM By sonnytle

Posted on Mar 16, 2017 02:04 AM

Hi, first of all thank you for what you do.  This is a great source of information.

I have a question about your ASP.NET Capture Screenshot code.  It works on my local PC, but when i deploy it to an IIS server and browse to it, it does not work.  When i click Capture, the page just spins forever.  Please let me know what i might be doing wrong.

 

Thank you,

Sonny Le

Results 1 - 5 of 7 12
Posted on Mar 16, 2017 09:15 AM

Hi sonnytle,

Does you have added reference to the given libraries in the iis.


Posted on Mar 16, 2017 09:28 AM

Hi dharmendr,

Thank you for the quick response.

Yes, i have added the two references to the website on IIS server:

1.  System.Windows.Forms

2.  System.Windows.Forms.DataVisualization.Design

 

It works on my local PC, but not on the IIS Server.

 


Posted on Mar 16, 2017 09:55 AM

Hi sonnytle,

As you can see the Demo is working. It might be some script file missing or incorrect path or javascript error. Please verify these.


Posted on Mar 16, 2017 10:02 AM

Hi dharmendr,

Do you think it might be because the System.Windows.Forms dll is a client side component so when used on the server side, it does not work?


Posted on Mar 16, 2017 10:52 AM

I have narrowed down to the while loop (shown in red font) that does does not complete.  The loops does not exit:

protected void Capture(object sender, EventArgs e)
{
string url = txtUrl.Text.Trim();
Thread thread = new Thread(delegate()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
browser.Navigate(url);
browser.Width = 1024;
browser.Height = 768;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}

private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser browser = sender as WebBrowser;
using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height))
{
browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] bytes = stream.ToArray();
imgScreenShot.Visible = true;
imgScreenShot.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
}
}
}