从umbraco渲染html内容

时间:2013-06-12 23:02:30

标签: c# asp-classic umbraco

我正在调用一个web api服务,该服务从umbraco(cms)获取一个文本页面,并在文字控件中显示它的关联xml。在比较源与httpwebrequest时,我得到奇怪的html输出。

我在页面加载中使用此代码来调用服务

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://111.111.111.111:8080/api/PageContentApi?id=1122");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream stream = response.GetResponseStream();
                using (StreamReader reader = new StreamReader(stream))
                {
                    string html = reader.ReadToEnd();
                    aboutText.Text = html;
                }
            }

我收到的字符串信息是:

[{"Id":1122,"Name":"sample","Alias":"bodyText","Value":"<p>This is a sample test</p>\r\n<p> </p>\r\n<p>two returns</p>\r\n<p> </p>\r\n<p>one return</p>\r\n<p>     spaces   spaces  <strong>bold  </strong><em> italic   </em><span style=\"text-decoration: underline;\">underline</span></p>\r\n<p> </p>\r\n<p><img width=\"201\" height=\"75\" src=\"http://111.111.111.111/media/1001/logo.gif\" alt=\"logo\"/></p>","Version":"b8cbd32e-b946-4b1f-ae72-2564b7757479","Created":"1/1/0001 12:00:00 AM","ParentId":-1}]

当我在执行get后手动查看firefox中的源代码时,我看到了完全不同的东西:

<ArrayOfPageContent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/name.Models"><PageContent><Alias>bodyText</Alias><Created>1/1/0001 12:00:00 AM</Created><Id>1122</Id><Name>sample</Name><ParentId>-1</ParentId><Value>&lt;p&gt;This is a sample test&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;two returns&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;one return&lt;/p&gt;
&lt;p&gt;     spaces   spaces  &lt;strong&gt;bold  &lt;/strong&gt;&lt;em&gt; italic   &lt;/em&gt;&lt;span style="text-decoration: underline;"&gt;underline&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img width="201" height="75" src="http://111.111.111.111/media/1001/logo.gif" alt="logo"/&gt;&lt;/p&gt;</Value><Version>b8cbd32e-b946-4b1f-ae72-2564b7757479</Version></PageContent></ArrayOfPageContent>

为什么我会看到不同类型的回复,以及将这些内容从umbraco抓取到asp网页的最佳方式是什么。

1 个答案:

答案 0 :(得分:3)

您从程序收到的信息是JSON格式,而Firefox则是以XML格式接收的。

如果您阅读了umbraco的文档,我没有使用过,很可能会有一个参数可以添加到GET URL以请求JSON或XML。