简体   繁体   English

asp.net html模板

[英]asp.net html templating

I am thinking about a really simple html templating system to implement in asp.net. 我正在考虑一个非常简单的html模板系统,要在asp.net中实现。

Basically given a .html file with a couple of placeholders like [menu] and [content] it would grab the appropriate data and merge it with the html and the display the page. 基本上给定一个带有几个占位符的.html文件,例如[menu]和[content],它将获取适当的数据并将其与html合并并显示页面。 I'd like to be able to use asp.net stuff like controls and postback but this isnt essential. 我希望能够使用asp.net控件和回发之类的东西,但这不是必需的。

How difficult would this be to implement it and how would you go about doing it? 实施它有多困难,您将如何去做? Also is a solution like this practical for a pretty low traffic cms website? 对于流量非常少的CMS网站,这样的解决方案是否也可行?

Writing your own template system is basically reinventing the wheel in ASP.NET. 编写您自己的模板系统基本上重新发明 ASP.NET。 I wouldn't recommend it unless you plan on learning more about wheels (in which case I'd say go for it). 除非您打算进一步了解车轮,否则我不会推荐它(在这种情况下,我会说)。

A better alternative would be to use the one that Microsoft provides as part of the framework, with Master Pages . 更好的替代方法是使用Microsoft作为框架一部分提供的Master Pages Microsoft has figured out the hard details of implementing a template system and even lets you nest templates within templates. Microsoft已经弄清楚了实现模板系统的硬性细节,甚至允许您将模板嵌套在模板中。 You can dynamically swap templates in & out if you want a different look. 如果您希望外观不同,可以动态地切入和切出模板。

For a CMS, I would say you're better off using master pages than creating your own. 对于CMS,我想您最好使用母版页而不是创建自己的母版页。

You could write an HTTP Module to redirect all incoming requests to a single ASPX page. 您可以编写HTTP模块以将所有传入请求重定向到单个ASPX页面。

This page could examine the original URL to work out what data to retrieve from the database and display it to the user. 该页面可以检查原始URL,以确定要从数据库检索哪些数据并将其显示给用户。

As the page is a standard ASPX page, you'll still be able to take advantage of post-backs, server controls etc. 由于该页面是标准的ASPX页面,因此您仍然可以利用回发,服务器控件等功能。

If you need pages that have different layouts and functionality, you could write a series of ASPX pages (treating each one as a different 'template', effectively). 如果您需要具有不同布局和功能的页面,则可以编写一系列ASPX页面(将每个页面有效地当作一个不同的“模板”来处理)。 Then, in your HTTP Module, you could look the page up in the database to work out which 'template' ASPX page you should redirect to. 然后,在HTTP模块中,您可以在数据库中查找页面,以找出应该重定向到哪个“模板” ASPX页面。

There's more information about writing an HTTP Module to redirect URLs here . 此处,有更多有关编写HTTP模块以重定向URL的信息 Make sure you read down to the part which tells you how to override the default form action to make sure your post-backs still work! 确保您已阅读了该部分,该部分告诉您如何覆盖默认的表单操作,以确保您的回发仍然有效!

Hope this helps - good luck! 希望这有帮助,祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM