суббота, 23 апреля 2011 г.

Webbrowser Control Screenshot works in ASP.Net Dev Server but not IIS


Quick Overview:  Webbrowser control that takes a screenshot of a website and converts it to a bitmap works in ASP.Net Development Server but not when deployed to IIS 7.  When in IIS, the bitmap will display "Navigation to the page was canceled."
Quick Facts:
  • IIS server (Win Server 2k8 R2) is on corporate domain (firewall cannot be disabled as it is controlled by Group Policy)
  • I inherited the app from another developer so the below code is not my own
  • The screen capture works on a different server (Win Server 2k8) with identical settings (as far as I can tell) in IE, IIS, Firewall, User Account Permissions, and Folder Access
  • No events are thrown (through Event Viewer)
  • App pool - v2.0, Integrated, Network Service (account needed as an SSRS report is generated (using the screenshoot) using the same account)
I feel this has to be a permission's issue on IIS as I am able to grab a legit screenshot from my ASP.NET Dev Server or when clicking a hyperlink (with the same web address) within the app but I do not know what other settings to check.  Any help or suggestions would be greatly appreciated
Code (most) to capture screenshot and convert to bitmap:
public Bitmap GenerateWebSiteThumbnailImage()
            {
                Thread m_thread = new Thread(new ThreadStart(_GenerateWebSiteThumbnailImage));
                m_thread.SetApartmentState(ApartmentState.STA);
                m_thread.Start();
                m_thread.Join();
                return m_Bitmap;
            }

            private void _GenerateWebSiteThumbnailImage()
            {
                WebBrowser m_WebBrowser = new WebBrowser();
                m_WebBrowser.ScrollBarsEnabled = false;
                m_WebBrowser.ScriptErrorsSuppressed = true;
                m_WebBrowser.Navigate(m_Url);
                m_WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
                while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete)
                    Application.DoEvents();
                m_WebBrowser.Dispose();
            }

            private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                WebBrowser m_WebBrowser = (WebBrowser)sender;
                m_WebBrowser.ClientSize = new Size(1024, 768);
                m_WebBrowser.ScrollBarsEnabled = true;
                m_Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
                m_WebBrowser.BringToFront();
                m_WebBrowser.DrawToBitmap(m_Bitmap, m_WebBrowser.Bounds);
                m_Bitmap = (Bitmap)m_Bitmap.GetThumbnailImage(m_ThumbnailWidth, m_ThumbnailHeight, null, IntPtr.Zero);
            }

Комментариев нет: