Copied to clipboard

Flag this post as spam?

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


  • Daniel Bardi 924 posts 2556 karma points
    Feb 12, 2011 @ 02:29
    Daniel Bardi
    0

    Attach to umbraco.aspx Load Event

    I need to insert dynamic javascript into umbraco.aspx

    What is the easiest way to attach to the Load even for /umbraco/umbraco.aspx.

    I can do this with pages based on umbracoPage class, but not the umbraco.aspx.

    Any direction would be helpful.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 12, 2011 @ 02:39
    Lee Kelleher
    0

    Hi Daniel,

    Take a look at how we've done this on uComponents with the UI modules - we couldn't find a direct way to hook into the Page Events, so ended up using a HttpModule to do it.

    http://ucomponents.codeplex.com/SourceControl/changeset/view/72953#1411916

    Cheers, Lee.

  • Daniel Bardi 924 posts 2556 karma points
    Feb 12, 2011 @ 10:45
    Daniel Bardi
    0

    Lee,

    Thanks.. I'll have a look... odd.. I didn't know that default.aspx transfered to umbraco.aspx

    This is helpful.

  • Daniel Bardi 924 posts 2556 karma points
    Feb 12, 2011 @ 13:48
    Daniel Bardi
    0

    That worked!!!   Thanks!

    Q:  Why doesn't  BasePage.Current.Load  work?

  • Daniel Bardi 924 posts 2556 karma points
    Feb 14, 2011 @ 23:47
    Daniel Bardi
    1

    Here's some additional information I've discovered.

    I created a class based on the IHttpModule interface... works great when registered in the web.config

    No problem.. right?  Well there is in my case.  I didn't want to have to add the registration to the web.config during the package install.. I like things to run as a single unit and this sort of added an additional step to my thought process and I didn't like it.

    After searching the net, I came upon a wonderful solution to my "problem"... I can now register my HttpModule dynamically in my code which is what I wanted.

    This is how to do it:

    Add a reference to Microsoft.Web.Infrastructure and be sure to add the assembly to your package so it's copied to the bin folder.
    Create a static method in a class (mine's in the class that inherits from ApplicationBase callled ApplicationEventsHandler since I attach to other events there)

      private static bool _modulesRegistered;
            public static void RegisterModules()
            {
                if (_modulesRegistered) return;
                _modulesRegistered = true;
                DynamicModuleUtility.RegisterModule(typeof(MyHttpModule));
            }

    Then add the following call to your class file (before your class declaration)

    [assembly: PreApplicationStartMethod(typeof(ApplicationEventsHandler), "RegisterModules")]

     

    The DynamicModuleUtility.RegisterModule method will register your HttpModule on PreApplicationStart and removes the need to register the modules in web.config.

    Note: this only works with .Net 4.0... haven't tested with 3.5.

    Here's a link to the blog post that saved me: http://www.paraesthesia.com/archive/2011/02/08/dynamic-httpmodule-registration-in-asp-net-4-0.aspx

    Hope this was helpful to all you package developers!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies