Using a CMS, the HTML for our sitemap section on the sitemap page is being generated upon publishing of the sitemap page. So in essence, the sitemap.aspx page is sitting as static HTML on our web servers:
使用CMS时,站点地图页面上的站点地图部分的HTML将在发布站点地图页面时生成。所以从本质上讲,sitemap.aspx页面在我们的Web服务器上作为静态HTML:
Sitemap.aspx:
Sitemap.aspx:
<ul>
<li><a href="/">Home Page</a>
<li><a href="/etc.aspx">etc</a>
</ul>
This is great and all, but we're involved in a crusade for separation of concerns and doing away with server side pre-generated HTML. So the CMS is now generating the JSON data needed to build the sitemap section on the aspx page. So the page is now dynamic with an embedded data source like this:
这很棒,但是我们参与了一个讨论分离问题和取消服务器端预生成HTML的讨伐。因此CMS现在生成在aspx页面上构建站点地图部分所需的JSON数据。因此,该页面现在是动态的,具有如下嵌入式数据源:
[ { Title: "Home Page", Url: "/" }, { Title: "etc", Url: "/etc.aspx" } ]
<ul>
<% foreach(var page in Pages) { %>
<li><a href="<%: page.Url %>"><%: page.Title %></a></il>
<% } %>
</ul>
The Challenge here is getting ahold of the data to deserialize it into a strongly typed object.
这里的挑战是获取数据以将其反序列化为强类型对象。
I have explored:
我探索过:
- Inserting the data as a field of the page so it can be read in the code behind:
- 将数据作为页面字段插入,以便可以在后面的代码中读取:
<%@ Page Language="C#" AutoEventWireup="true" nherits="SiteMapPage" Data="@@SiteTreeData@@" %>
<%@ Page Language =“C#”AutoEventWireup =“true”nherits =“SiteMapPage”Data =“@@ SiteTreeData @@”%>
Which renders to:
其中呈现:
<%@ Page Language="C#" AutoEventWireup="true" nherits="SiteMapPage" Data="{ Large amount of json data }" %>
<%@ Page Language =“C#”AutoEventWireup =“true”nherits =“SiteMapPage”数据=“{大量的json数据}”%>
- Or also creating a custom user control to wrap the JSON where it can be read in the code behind:
- 或者还创建一个自定义用户控件来包装JSON,在后面的代码中可以读取它:
<A:JsonTransport runat="server" ID="SiteTreeData">@@SiteTreeData@@ </A:JsonTransport>
<答:jsontransport runat="“server”ID" =“sitetreedata”> @@ SiteTreeData @@
Which renders to:
其中呈现:
<A:JsonTransport runat="server" ID="SiteTreeData">{ Large amount of json data } </A:JsonTransport>
<答:jsontransport runat="“server”ID" =“sitetreedata”> {大量的json数据}
So that I can grab it in the code behind:
这样我就可以在后面的代码中抓住它:
this.Data= container.Controls.OfType<LiteralControl>().FirstOrDefault().Text;
In either case, I run into an exception when loading the page:
在任何一种情况下,我在加载页面时遇到异常:
System.Web.HttpCompileException (0x80004005): (0): error CS1647: An expression is too long or complex to compile
System.Web.HttpCompileException(0x80004005):( 0):错误CS1647:表达式太长或太复杂而无法编译
I believe it's because the rendered json string can be very large; in upwards of 1mb.
我相信这是因为渲染的json字符串可能非常大;超过1mb。
So, my question is, what is the best practices/approach/guidance for storing large rendered serialized data in the aspx page so that it can be read and deserialized in the code behind with optimal performance in mind?
所以,我的问题是,在aspx页面中存储大型渲染的序列化数据的最佳实践/方法/指导是什么,以便可以在后面的代码中读取和反序列化,同时考虑到最佳性能?
1 个解决方案
#1
0
ASPX is not meant to be used that way.
ASPX并不意味着以这种方式使用。
The best i can figure out - use what your CMS produces as an XML file, load it in codebehind, cache as necessary and and serve your dynamic pages using that.
我能想到的最好的东西 - 使用CMS生成的XML文件,在代码隐藏中加载它,根据需要缓存并使用它来提供动态页面。
var xml = @"<ul>
<li><a href=""/"">Home Page</a></li>
<li><a href=""/etc.aspx"">etc</a></li>
</ul>";
var document = XElement.Parse(xml); // You could use XElement.Load(Server.MapPath("~/App_Data/fileName.xml")) as well
this.Pages = document
.Elements("li")
.Select(li=>li.Element("a"))
.Select(el=>new Page{Url = el.Attribute("href").Value, Title = el.Value}).ToList();
#1
0
ASPX is not meant to be used that way.
ASPX并不意味着以这种方式使用。
The best i can figure out - use what your CMS produces as an XML file, load it in codebehind, cache as necessary and and serve your dynamic pages using that.
我能想到的最好的东西 - 使用CMS生成的XML文件,在代码隐藏中加载它,根据需要缓存并使用它来提供动态页面。
var xml = @"<ul>
<li><a href=""/"">Home Page</a></li>
<li><a href=""/etc.aspx"">etc</a></li>
</ul>";
var document = XElement.Parse(xml); // You could use XElement.Load(Server.MapPath("~/App_Data/fileName.xml")) as well
this.Pages = document
.Elements("li")
.Select(li=>li.Element("a"))
.Select(el=>new Page{Url = el.Attribute("href").Value, Title = el.Value}).ToList();