Copied to clipboard

Flag this post as spam?

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


  • Luc G. 3 posts 23 karma points
    Sep 08, 2009 @ 19:21
    Luc G.
    0

    Accessing current node in a HTTPModule

    Hi,

    I try to retrieve the current node in a HTTPmodule but "umbraco.presentation.nodeFactory.Node.GetCurrent()" always return null.

    How can I access the current node in a HTTPModule?

    Thanks,

    L.

  • Bogdan 250 posts 427 karma points
    Sep 08, 2009 @ 20:09
    Bogdan
    0

    you can try Document current = new Document(Node.GetCurrent().Id);

  • Luc G. 3 posts 23 karma points
    Sep 08, 2009 @ 20:14
    Luc G.
    0

    Like I said, Node.GetCurrent() always return NULL in my HTTPModule. Maybe it's too early in the umbraco process and the "context" is not already set.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 09, 2009 @ 00:42
    Aaron Powell
    0

    Try constructing a new instance of a Node using the UmbracoContext as the ID source:

    var node = new Node(UmbracoContext.Current.PageId.Value);

    PageId is a nullable int (int?) so make sure you null check it first

  • Luc G. 3 posts 23 karma points
    Sep 14, 2009 @ 14:58
    Luc G.
    0

    The PageID is always Null at this time.

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 14, 2009 @ 15:41
    Ismail Mayat
    0

    Luc,

    You could try getting the full path of page being requested from server object  then try umbraco.library.GetXmlNodeByXPath from there get the doc id then do as per slace's suggestion?  Not very clean but I do recall doing something similar a while back.

    Regards

    Ismail

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 16, 2009 @ 05:40
    Aaron Powell
    0

    Hmm... I'll have a look at when the context is created vs when you're executing your request

  • Paul Sterling 719 posts 1556 karma points MVP 9x admin c-trib
    Sep 16, 2009 @ 07:29
    Paul Sterling
    0

    I have not been able to get the Current node (at least not in any sort of convenient manner) in a HTTP Module (or generic handler) so far...always fallen back on a less-than-elegant hack.  Which brings up an intersting question we've debated a bit:

    If you are executing in a Module (or handler) *IS* there a Current Node?

    Not adding lots to this thread but perhaps the solution will help answer the question.

    -Paul

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 16, 2009 @ 10:18
    Aaron Powell
    0

    Oh good point Paul, since a Module is executed within the request pipeline of IIS regardless of the request type ;)

    If you're after a less-than-elegant hack you could always access HttpContext.Items["pageID"], that *may* be set (it's actually what is used internally by the UmbracContext)

Please Sign in or register to post replies

Write your reply to:

Draft