Creating html-file from asp.net ?

P

Petri

Dear co-programmers,

let's suppose that we have a database where clients
can update their contact information.

Is it possible to create (a static) html-page also
about that information from asp.net page ?

That would be important because that way people would
also find the information using search engines.

I am using asp.net framework 1.1, VB.NET and sql server 2000.
I searched the google but did not find any good information.

I would appreciate any help, code etc.

best regards, Petri
 
C

Chad Z. Hower aka Kudzu

Petri said:
That would be important because that way people would
also find the information using search engines.

You dont need a static page. ASP caches pages generations for performance,
and search engines will search ASP pages too.
 
R

Rick Strahl [MVP]

Hi Petri,

As Chad points out there much less reason to rely on static pages in ASP.Net
for performance reasons because there are many mechanisms both automatic and
under your control that optimize out put that stays the same over hits
nicely. Generally if your content changes it's often much better to just
take the small perf hit rather than deal with the admin overhead of
generating pages and keeping them up to date IMHO.

However if you really need to generate HTML output from an ASPX page it can
be easily done by overriding the Render method and capturing the output from
the TextWriter. This looks something like this:

protected override void Render(HtmlTextWriter writer)

{

// *** Write the HTML into this string builder

StringBuilder sb = new StringBuilder();

HtmlTextWriter hWriter = new HtmlTextWriter(new StringWriter(sb));

base.Render(hWriter);

// *** store to a string

string PageResult = sb.ToString();

// *** Write it back to the server's HTTP Stream -
// *** skip this if you don't want to display the rendered content

writer.Write(PageResult);

.... PageResult now hold the HTML content you can write out to disk
do whatever you want to with.

}

This example goes to string but you can use a StreamWriter instead of string
builder to dump the output directly to file if you wish.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top