将asp或asp.net页面(同时包括页面和代码)保存为Txt文件或保存到数据库中,
然后编程从数据库中读取该数据,并发送给界面。如果单纯是HTML,没有代码,则直接用Response.Write(data)就可以了,但是如果有代码,这样输出后代码被看成是普通文本,并不执行,请问如何才能使代码执行呢?

解决方案 »

  1.   

    利用WebClient 和 WebRequest
      

  2.   

    提供向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法。不能继承此类。
    [Visual Basic]
    <ComVisible(True)>
    NotInheritable Public Class WebClient
       Inherits Component
    [C#]
    [ComVisible(true)]
    public sealed class WebClient : Component
    [C++]
    [ComVisible(true)]
    public __gc __sealed class WebClient : public Component
    线程安全
    此类型的所有公共静态(Visual Basic 中为 Shared)成员对多线程操作而言都是安全的。但不保证任何实例成员是线程安全的。备注
    WebClient 类提供向 URI 标识的任何本地、Intranet 或 Internet 资源发送数据以及从这些资源接收数据的公共方法。WebClient 类使用 WebRequest 类提供对 Internet 资源的访问。WebClient 实例可以通过任何已向 WebRequest.RegisterPrefix 方法注册的 WebRequest 子代访问数据。注意   默认情况下,.NET 框架支持以 http:、https: 和 file: 方案标识符开头的 URI。
    WebClient 类提供四种将数据上载到资源的方法: OpenWrite 返回一个用于将数据发送到资源的 Stream。 
    UploadData 将字节数组发送到资源并返回包含任何响应的字节数组。 
    UploadFile 将本地文件发送到资源并返回包含任何响应的字节数组。 
    UploadValues 将 NameValueCollection 发送到资源并返回包含任何响应的字节数组。 
    WebClient 类还提供三种从资源下载数据的方法: DownloadData 从资源下载数据并返回字节数组。 
    DownloadFile 从资源将数据下载到本地文件。 
    OpenRead 从资源以 Stream 的形式返回数据。 下面的示例创建一个 WebClient 实例,然后使用该实例从服务器下载数据并将其显示在系统控制台上、从服务器下载数据并将其写入文件、以及将窗体值上载到服务器并接收响应。[Visual Basic] 
    Public Shared Sub Main()
        Try
            Dim client As New WebClient()
            Dim pageData As [Byte]() = client.DownloadData("http://www.contoso.com")
            Dim pageHtml As String = Encoding.ASCII.GetString(pageData)        ' Download the data to a buffer.
            Console.WriteLine(pageHtml)
            
            ' Download the data to a file.
            client.DownloadFile("http://www.contoso.com", "page.htm")
            
            
            ' Upload some form post values.
            dim form as New NameValueCollection()
                form.Add("MyName", "MyValue")              ' Note that you need to replace "http://localhost/somefile.aspx" with the name of 
                ' a file that is available to your computer.
                Dim responseData As [Byte]() = client.UploadValues("http://www.contoso.com/form.aspx", form)      
            Console.WriteLine(Encoding.ASCII.GetString(responseData))
        
        Catch webEx As WebException
            if webEx.Status = WebExceptionStatus.ConnectFailure then
               Console.WriteLine("Are you behind a firewall?  If so, go through the proxy server.")
            end if
            Console.Write(webEx.ToString())
        End Try
        End Sub 'Main
    [C#] 
    try {
             
          // Download the data to a buffer.
                 WebClient client = new WebClient();        Byte[] pageData = client.DownloadData("http://www.contoso.com");
          string pageHtml = Encoding.ASCII.GetString(pageData);
          Console.WriteLine(pageHtml);      // Download the data to a file.
                  client.DownloadFile("http://www.contoso.com", "page.htm");      // Upload some form post values.
          NameValueCollection form = new NameValueCollection();      
          form.Add("MyName", "MyValue");      
          Byte[] responseData = client.UploadValues("http://www.contoso.com/form.aspx", form);      }
    catch (WebException webEx) {
         Console.WriteLine(webEx.ToString());
          if(webEx.Status == WebExceptionStatus.ConnectFailure) {
             Console.WriteLine("Are you behind a firewall?  If so, go through the proxy server.");
          }
      

  3.   

    从数据库读取出来的页面信息(包括页面与代码)是存贮在一个字符串变量中,我还是不明白如何让服务器解析后生成纯的HTML发送给客户端???
    继续呀,急
      

  4.   

    难道将数据库读取的页面数据保存成一个临时文件(xxxx.aspx),然后再通过WebClient 获取??