dynamic link creatation

Discussion in 'ASP .Net' started by Steve, May 25, 2005.

  1. Steve

    Steve Guest

    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
    Steve, May 25, 2005
    #1
    1. Advertising

  2. Steve

    Guest

    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
    , May 25, 2005
    #2
    1. Advertising

  3. 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




    "Steve" <> wrote in message
    news:...
    > 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
    >
    >
    William F. Robertson, Jr., May 25, 2005
    #3
  4. 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!
    ***************************


    "Steve" wrote:

    > 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
    >
    >
    >
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, May 25, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    795
    Kevin Spencer
    May 17, 2005
  2. Graham Thomson
    Replies:
    3
    Views:
    442
    Eki Y. Baskoro
    Dec 18, 2003
  3. Replies:
    15
    Views:
    4,622
    dorayme
    Jan 7, 2006
  4. Dan M
    Replies:
    5
    Views:
    411
  5. kolesdz
    Replies:
    9
    Views:
    519
    Blinky the Shark
    Aug 22, 2007
Loading...

Share This Page