开发者

Static website from ASP.NET website

A few clients have asked to make some static websites because their hosting doesn't support a server-side language. Now I was wondering are there any tools/techniques for generating a static website from an Asp.net site?

The reason I ask is because without masterpage or any form of templating it gets really cumbersome.

I rememb开发者_开发技巧er 5 years ago Dreamweaver had a templating system based on html comments but I didn't like it much so I would like to avoid that.


Check out the RenderControl method. It will essentially let you dump the contents of any ASP.NET page as HTML. So you can build your site dynamically, then dump it all out to HTML and upload it to your antique server.

Here's a bit of helper code that I swiped from one of my projects to get the contents of any page into a string:

public class RenderHelper
{
    public static string RenderControl(Control control)
    {
        StringBuilder result = new StringBuilder(1024);
        control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
        return result.ToString();
    }
    public static string RenderControl(TemplateControl control)
    {
        StringBuilder result = new StringBuilder(1024);
        control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
        return result.ToString();
    }
    public static string RenderPage(string pageLocation)
    {
        HttpContext context = HttpContext.Current;
        StringBuilder result = new StringBuilder(1024);
        context.Server.Execute(pageLocation, new HtmlTextWriter(new StringWriter(result)));
        return result.ToString();
    }
}


You could link a js file to any new pages you make. Eg a file that has functions for writing out the footer and header and essentially let the js write the html. This is a pseudo web template a bit like php include or master page approach but without any server side stuff.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜