Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Thomas Dolberg 74 posts 95 karma points
    Nov 28, 2011 @ 00:25
    Thomas Dolberg

    Calling method when umbracocontext has loaded

    I need to create quite a lot of urlrewrite-rules to catch different urlrewriting scenarioes. So I began defining the rules in urlrewriting.config but it slowed down my site considerably, so I decided to write my own rewriting provider and create a dictionary with exact matches on the incoming URLs and cache the dictionary.This solution seems to be really fast compared to my previous regex-rules in urlrewriting.config.

    I would like to build the dictionary on application start, so I inherited from ApplicationBase. The problem is, that at this point the umbracocontext is not available and I need the niceUrl of some nodes to put in the dictionary. I also tried fetching the nodes as documents directly from the DB and use the umbraco.library.NiceUrl. None of these work because the umbracocontext is not available yet. 

    For testing purposes I tried creating a page with a button, which would call the exact same code to build the dictionary. This works perfectly because the umbracocontext has been created at this point. But I need the code to run on application start.

    I then tried creating the UmbracoContext in my code on application start, but then I get the following exception:

    "The current httpContext can only be set once during a request"

    So my question is, how can I call a method right after umbracocontext has been loaded?




Please Sign in or register to post replies

Write your reply to: