After reading Jeff's article about the importance of sitemaps, so I decided to generate one for my dynamic website.

I saw some articles about how to implement it with ASP.NET but every solution I saw showed how to generate it on the fly with an HTTP Handler.

But that solution means that every time someone asks for the file, my code has to iterate trought all my entries to re-generate one?

Wouldn't it be less resource consuming to generate it incrementally? For example on stackoverflow, every time a user adds a question, appending the new URL node?

+1  A: 

You might want to cache the resulting XML and invalidate the cache whenever your site structure changes. This might lead to having a publish/subscribe mechanism for components of your web site, but in case of properly structured application this won't be a problem.

Anton Gogolev
+1  A: 

You mean cache the result? Yes there's no reason you couldn't do that. Depending on the amount of traffic your site is getting it might be unnecessary but if you're doing it simply to improve your technique there's a number of ways to approach it.

Spencer Ruport