Krunal Krunal -4 years ago 96
ASP.NET (C#) Question

Generate Static HTML Pages to replace dynamic pages

For one project, we've to generate static .html pages, which are gonna to be published on the same server to serve to millions of visitors.

We've to automate the creation of those files from a c# code, which takes data from a SQL Server database.

The project is already developed using C# MVC3, and we need to store the dynamically generated pages in .html on the same url to be served to visitors.

I was wondering how to use MVC3/Razor to generate those .html pages?

I don't want/need to use web caching, for a lot of reasons(load(millions of pages loaded every day), these static pages will be cached on CDN network to further serve super fast without original server going into picture, number of pages are really too many (caching will only help me if I've the same pages a lot of time, but I will have more than million pages visited very frequently, so I will have to generate them often.)

So I really search something to generate HTML pages.

Any idea how to do this...

Answer Source

If you want to generate html based on the mvc views and models, you could use the Razor. I have used it to generate email templates, where we have used the Razor to inject the model into a view. You could generate the html from the views and write them into static html files if that fits your purpose. Refer Razor Engine from NuGet, And you could use it like

var html = Razor.Parse(templateView, model);

If you want more customization on it, May be this tutorial could help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download