dynamic link creatation

S

Steve

Hi-
I am interested in creating links within my pages dynamically as they are
requested. For example, someone requests a page, my web app. would parse
the generated *.aspx HTML and add links to words or phrases that my app
deems appropriate.

I have tried to think of the best way to do this, the most efficient way.
It doesn't have to be done each time it's requested, I would actually prefer
if it were cached one it is done. I am trying to avoid maintaining upwards
of 100 links per page and would like to automate if possible.

I am interested in suggestions. All I have come up with is to use the Page
class to access the rendered HTML and process and modify that string. Is
this a good way to go about this?

Thank You,
Steve
 
G

garethdjames

I would not parse the html (raw) after it was created,

Instead once the page has been rendered (use the render event),

Then loop through all controls on the page, if it is a literal control
(i.e. just text) you can then pattern match it (possibly Regex) to see
if you need to replace the text with links.

Replace any text with links (dynamically create the controls),

Finally have a look at output caching, this allows the HTML to be
cached so that you don't need to create it each time,

Hope this helps
 
W

William F. Robertson, Jr.

Two suggestions:

You can use the Filter property of the HttpResponse object. This is a
Stream derived object that you can use to manipulate the outgoing response.

http://aspalliance.com/71

You can place all your "custom links" into a UserControl and set the
OutputCache on it, so it will only have to be calculated once.

bill
 
G

Guest

That is an interesting way of handling this, but I am not sure I agree. You
have two suggestions thus far and I will add a third (a bit rough, perhaps,
as I did not really do any design work):

I would consider making the entire page creation dynamic rather than attempt
to loop through the "rendered" HTML. One option then is to have a program run
through each bit of output (stored in a database most likely) and add the
tags you need. The new string can be stored in another column (database) or
cached in the ASP.NET caching mechanism (done on the fly or ahead of time).

Gareth's suggestion: Loop through controls. This is possible, but it can be
problematic if you do not follow Microsoft best practices (ie, have a lot of
hybrid HTML/ASP.NET).

William's suggestion: Filter ASP.NET traffic. I like the idea of using Http
handlers or filters, etc. to control output. You can cache here, as well. The
benefit is you do not have to write the handler more than once to have every
page with links added. The only negative is the coding is a bit more complex
with you use these objects. It is worth it, however.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top