1

I have a Web Forms app solution made with Visual Studio 2013 and I want to generate static HTML pages from it. Does anyone know a good tool or maybe script and had experience with this?

I tried with Pretzel, but it does not support ASP.

2
  • Is there a particular reason you're looking to generate a static pages from the ASP.NET pages? Just making sure there isn't a better solution. Commented Sep 12, 2014 at 14:46
  • @Kirk "You need to find some tool or VS plugin or IIS plugin or similar that can easily do this. The plan is that all those Default.aspx and other .aspx pages will be generated as static html. Default.aspx -> Default.html, Page1.aspx -> Page1.html etc... The result after the tool is run should be a list of ordinary html pages, without any need of any background cs code. " My task. Commented Sep 12, 2014 at 14:54

2 Answers 2

1

You can generate HTML pages using HtmlTextWriter as:

using (StreamWriter sw = new StreamWriter(Server.MapPath("fileName.html")))
using (HtmlTextWriter writer = new HtmlTextWriter(sw))
{
    writer.RenderBeginTag(HtmlTextWriterTag.Html);

    writer.RenderBeginTag(HtmlTextWriterTag.Head);
    writer.Write("Head Contents");
    writer.RenderEndTag();

    writer.RenderBeginTag(HtmlTextWriterTag.Body);
    writer.Write("Body Contents");
    writer.RenderEndTag();

    writer.RenderEndTag();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer, but I had problems with rendering.
0

Here is the code I used and it is working fine:

Uri url = new Uri(serverPath + pageName);
WebClient wc = new WebClient();
wc.Headers.Add(HttpRequestHeader.Accept,"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0");

string finalHTML = wc.DownloadString(url);

//change the asp extensions if there are any linking
finalHTML = finalHTML.Replace(".aspx", ".html");    

//create HTML file
System.IO.File.WriteAllText(string.Format("{0}{1}", filePathSave, pageName), finalHTML);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.