如何让渗透允许IIS中的STA线程 [英] how to give the permeation to allow the STA threads in IIS

查看:76
本文介绍了如何让渗透允许IIS中的STA线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我使用下面的代码请求正在运行但没有得到响应..当我使用 STA线程



如何让渗透率允许IIS中的STA线程



Hi ,

when i am using below code request is running but not getting the response.. when i am using the STA threads

how to give the permeation to allow the STA threads in IIS

public partial class Test : Page
{
    bool snap = false;
    protected void CreateThumbnailImage(object sender, EventArgs e)
    {            
        snap = true;
    }
    protected override void Render(HtmlTextWriter writer)
    {
        if (snap)
        {
            int width = Int32.Parse(txtWidth.Text);
            int height = Int32.Parse(txtHeight.Text);
            StringBuilder builder = new StringBuilder();
            HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(builder));
            base.Render(htw);
            string html = builder.ToString();
            Thumbnail thumbnail = new Thumbnail(html, 800, 600, width, height, Thumbnail.ThumbnailMethod.Html);
            Bitmap image = thumbnail.GenerateThumbnail();
            image.Save(Server.MapPath("~") + "/Thumbnail.bmp");                
            writer.Write(html);
            writer.Write("<img src=\"Thumbnail.bmp\" />");
        }
        else
            base.Render(writer);
    }
}
public class Thumbnail
{
    public enum ThumbnailMethod { Url, Html };
    public string Url { get; set; }
    public Bitmap ThumbnailImage { get; set; }
    public int Width { get; set; }
    public int Height { get; set; }
    public int BrowserWidth { get; set; }
    public int BrowserHeight { get; set; }
    public string Html { get; set; }
    public ThumbnailMethod Method { get; set; }
 
    public Thumbnail(string data, int browserWidth, int browserHeight, int thumbnailWidth, 
                                    int thumbnailHeight, ThumbnailMethod method)
    {
        this.Method = method;
        if (method == ThumbnailMethod.Url)
            this.Url = data;
        else if (method == ThumbnailMethod.Html)
            this.Html = data;
        this.BrowserWidth = browserWidth;
        this.BrowserHeight = browserHeight;
        this.Height = thumbnailHeight;
        this.Width = thumbnailWidth;
    }
    public Bitmap GenerateThumbnail()
    {
        Thread thread = new Thread(new ThreadStart(GenerateThumbnailInteral));
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();
        return ThumbnailImage;
    }
    private void GenerateThumbnailInteral()
    {
        WebBrowser webBrowser = new WebBrowser();
        webBrowser.ScrollBarsEnabled = false;
        if (this.Method == ThumbnailMethod.Url)
            webBrowser.Navigate(this.Url);
        else webBrowser.DocumentText = this.Html;
        webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
        while (webBrowser.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
        webBrowser.Dispose();
    }
    private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser webBrowser = (WebBrowser)sender;
        webBrowser.ClientSize = new Size(this.BrowserWidth, this.BrowserHeight);
        webBrowser.ScrollBarsEnabled = false;
        this.ThumbnailImage = new Bitmap(webBrowser.Bounds.Width, webBrowser.Bounds.Height);
        webBrowser.BringToFront();
        webBrowser.DrawToBitmap(ThumbnailImage, webBrowser.Bounds);
        this.ThumbnailImage = (Bitmap)ThumbnailImage.GetThumbnailImage(Width, Height, null, IntPtr.Zero);
    }
}

推荐答案

您不能在ASP.NET应用程序中使用WebBrowser控件。 />


首先,没有任何意义,因为ASP.NET应用程序中的所有代码都完全在SERVER上运行! ASP.NET应用程序的用户永远不会看到您的Web浏览器控件。
You can NOT use a WebBrowser control in an ASP.NET app.

First, there is no point to it because all of the code in an ASP.NET app runs entirely on the SERVER! The users of your ASP.NET application will never see your web browser control.


这篇关于如何让渗透允许IIS中的STA线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆