Copied to clipboard

Flag this post as spam?

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


  • Dominic Pettifer 51 posts 50 karma points
    Mar 16, 2009 @ 16:08
    Dominic Pettifer
    0

    TypeInitializationException throw when calling Node.GetCurrent() in external Library

    Hi,

    We're building an external library that queries a search indexing system we use. The library is designed to be dropped into any web project, including umbraco sites.

    Now, when it's being used in an Umbraco site, we want to take advantage of some Umbraco features by getting the current page node via Node.GetCurrent(). If Node.GetCurrent() is called in a standard non-Umbraco ASP.NET website project, then GetCurrent() will throw a NullReferenceException which can catch in a try/catch block, so no problem. However, somewhere somehow, a TypeInitializationException is being thrown when a call to Node.GetCurrent() is made, and it's not being caught by our try/catch block.

    [code]try
    {
    Node currentPage = Node.GetCurrent();
    // Do something with current page
    }
    catch
    {
    // Not an Umbraco website, so do something else
    }[/code]

    So I guess the question is, is there some programmic way we get detect whether or not we're executing inside an Umbraco instance, or an ordinary ASP.NET website?

    My work colleague had the idea of detecting the presense of the /data/umbraco.config file, does this seem a good idea, to you?

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 16, 2009 @ 16:43
    Ismail Mayat
    0

    Dominic,

    You could try and test for querystring umbPage if that is not present then you are not in umbraco site? in umbraco when u view page the httphandler gives you mysite/mypage.aspx but under the hood the actual request is default.aspx?umbPage=1234 etc

    Regards

    Ismail

  • okaseeh 1 post 20 karma points
    Mar 16, 2009 @ 17:21
    okaseeh
    0

    Hi Dominic,

    You could try this,

    try
    {
    if (File.Exists(HttpContext.Current.Server.MapPath("/data/umbraco.config")))
    {
    XmlNode node = ((IHasXmlNode)library.GetXmlNodeById(Node.GetCurrent().Id.ToString()).Current).GetNode();

    }
    }
    catch
    {
    }

    Thanks,
    Osama

Please Sign in or register to post replies

Write your reply to:

Draft