我能从ASP渲染html吗?NET页面对象。网络应用程序?

时间:2020-12-30 02:01:32

I'm not talking about hosting ASP.NET with the 'ApplicationHost' class. For example, if I create a Console application, create a valid HttpContext object and pass it to the ProcessRequest of a custom Page object, will it fill the HttpReponse html like if it was running inside ASP.NET?

我说的不是ASP。NET具有“ApplicationHost”类。例如,如果我创建一个控制台应用程序,创建一个有效的HttpContext对象,并将其传递给自定义页面对象的ProcessRequest,它会像在ASP.NET中运行时那样填充HttpReponse html吗?

2 个解决方案

#1


3  

I don't see why not.

我不知道为什么。

Try the RenderControl() method to get the html from a page or Web control.

尝试RenderControl()方法从页面或Web控件获取html。

static public string GetHTML(Control myControl)
{
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter myWriter = new HtmlTextWriter(sw);
        myControl.RenderControl(myWriter);
        return sw.ToString();
}

I use this to render GridViews asynchronously.

我使用它异步地呈现gridview。

#2


0  

If you're talking custom ASP.NET controls, then you can programmatically create them and get them to render to a string easily enough. If that's something you're interested in doing, then I've done it in the past and can dig the code out for you.

如果你说的是定制ASP。NET控件,然后您可以编程地创建它们,并使它们很容易地呈现到字符串中。如果这是您感兴趣的事情,那么我在过去已经做过了,可以为您挖掘代码。

#1


3  

I don't see why not.

我不知道为什么。

Try the RenderControl() method to get the html from a page or Web control.

尝试RenderControl()方法从页面或Web控件获取html。

static public string GetHTML(Control myControl)
{
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter myWriter = new HtmlTextWriter(sw);
        myControl.RenderControl(myWriter);
        return sw.ToString();
}

I use this to render GridViews asynchronously.

我使用它异步地呈现gridview。

#2


0  

If you're talking custom ASP.NET controls, then you can programmatically create them and get them to render to a string easily enough. If that's something you're interested in doing, then I've done it in the past and can dig the code out for you.

如果你说的是定制ASP。NET控件,然后您可以编程地创建它们,并使它们很容易地呈现到字符串中。如果这是您感兴趣的事情,那么我在过去已经做过了,可以为您挖掘代码。