将 ASPX 导出为 HTML

发布于 2024-07-04 06:42:26 字数 313 浏览 5 评论 0原文

我们正在构建一个 CMS。 该网站将由用户在 aspx 页面中构建和管理,但我们希望创建一个 HTML 的静态网站。 我们现在的做法是使用我在此处找到的代码重载 Aspx 页面中的 Render 方法并将 HTML 字符串写入文件。 这对于单个页面来说效果很好,但我们的 CMS 的问题是,我们希望从一开始就自动为网站创建一些 HTML 页面,甚至在创建者编辑系统中的任何内容之前。 有谁知道有什么方法可以做到这一点?

We're building a CMS. The site will be built and managed by the users in aspx pages, but we would like to create a static site of HTML's.
The way we're doing it now is with code I found here that overloads the Render method in the Aspx Page and writes the HTML string to a file. This works fine for a single page, but the thing with our CMS is that we want to automatically create a few HTML pages for a site right from the start, even before the creator has edited anything in the system.
Does anyone know of any way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

审判长 2024-07-11 06:42:26

@ckarras:我宁愿不使用外部工具,因为我希望以编程方式而不是手动创建 HTML 页面。

@jttraino:我没有需要输出站点的时间间隔 - 当用户创建新站点时必须发生 uotput。

@Frank Krueger:我真的不明白如何使用 WebContext 和 WebRequest 创建页面的实例。

我在 searchdotnet 中搜索“wget”,并到达 一篇关于名为 WebClient 的 .net 类的帖子。 如果我使用 DownloadString() 方法,它似乎可以实现我想要的功能 - 从特定网址获取字符串。 问题是,因为我们的 CMS 需要登录,所以当该方法尝试访问该页面时,它会被抛出到登录页面,因此返回 login.aspx HTML...

关于如何从这里继续的任何想法?

@ckarras: I would rather not use an external tool, because I want the HTML pages to be created programmatically and not manually.

@jttraino: I don't have a time interval in which the site needs to be outputted- the uotput has to occur when a user creates a new site.

@Frank Krueger: I don't really understand how to create an instance of my page using WebContext and WebRequest.

I searched for "wget" in searchdotnet, and got to a post about a .net class called WebClient. It seems to do what I want if I use the DownloadString() method - gets a string from a specific url. The problem is that because our CMS needs to be logged in to, when the method tries to reach the page it's thrown to the login page, and therefore returns the login.aspx HTML...

Any thoughts as to how I can continue from here?

网名女生简单气质 2024-07-11 06:42:26

我建议您以非常简单的方式执行此操作,而不要使用代码执行此操作。 它将允许您的 CMS 代码执行 CMS 代码应该执行的操作,并使其尽可能简单。

使用 HTTrack 等产品。 它称自己为“网站复制者”。 它抓取网站并创建 html 输出。 它快速且免费。 您可以让它以您认为最好的任何频率运行。

它将您的 HTML 输出需求与 CMS 设计和实施分离。 它降低了复杂性,并为您输出 HTML 的方式提供了一定的灵活性,而不会在 CMS 代码中引入故障点。

I recommend you do this a very simple way and don't do it in code. It will allow your CMS code to do what the CMS code should do and will keep it as simple as possible.

Use a product such as HTTrack. It calls itself a "website copier". It crawls a site and creates html output. It is fast and free. You can just have it run at whatever frequency you think is best.

It decouples your HTML output needs from your CMS design and implementation. It reduces complexity and gives you some flexibility in how you output the HTML without introducing failure points in your CMS code.

So尛奶瓶 2024-07-11 06:42:26

我似乎通过使用 Server.Ecxcute 方法找到了我的问题的解决方案。

我找到了一篇 文章 演示了它的用法:

TextWriter textWriter = new StringWriter();
Server.Execute("myOtherPage.aspx", textWriter);

然后我对 textWriter 做了一些操作,并将其插入到 html 文件中。 等等瞧! 有用!

I seem to have found the solution for my problemby using the Server.Ecxcute method.

I found an article that demonstared the use of it:

TextWriter textWriter = new StringWriter();
Server.Execute("myOtherPage.aspx", textWriter);

Then I do a few maniulatons on the textWriter, and insert it into an html file. Et voila! It works!

紫﹏色ふ单纯 2024-07-11 06:42:26

调用 Render 方法仍然非常简单。 只需创建页面的一个实例,创建一个存根 WebContext 以及 WebRequest 对象,然后调用页面的 Render 方法即可。 然后您就可以自由地对结果做任何您想做的事情。

或者,编写一些 curlwget 脚本来下载并存储您想要设为静态的页面。

Calling the Render method is still pretty simple. Just create an instance of your page, create a stub WebContext along with the WebRequest object, and call the Render method of the page. You are then free to do whatever you want with the results.

Alternatively, write a little curl or wget script to download and store whichever pages you want to make static.

内心激荡 2024-07-11 06:42:26

您可以使用 wget(命令行工具)递归查询每个页面并将其保存到 html 文件。 它将更新生成的 html 中的所有必要链接以引用 .html 文件而不是 .aspx。 这样,您就可以像使用服务器生成的页面一样对所有站点进行编码(更易于测试),然后将其转换为静态页面。

如果您仅出于性能原因需要静态 HTML,我的首选是使用 ASP.Net 输出缓存。

You could use wget (a command line tool) to recursively query each page and save them to html files. It would update all necessary links in the resulting html to reference .html files instead of .aspx. This way, you can code all your site as if you were using server-generated pages (easier to test), and then convert it to static pages.

If you need static HTML for performance reasons only, my preference would be to use ASP.Net output caching.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文