Copied to clipboard

Flag this post as spam?

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


  • burak 11 posts 92 karma points
    Jan 08, 2017 @ 10:52
    burak
    0

    Umbraco 6 nodeProperty Error

    the code is working in umbraco 4.7 but it is not working umb 6+ what is the problem

     <%@ Import namespace="umbraco.presentation.nodeFactory" %>
    
    
    
    
    
    
    
    
    
    <script runat="server">protected void Page_Load(object sender, EventArgs e)
        {
    
    
           Node curNode = Node.GetCurrent();
        string red="";  
    
    
        Property nodeProperty = curNode.GetProperty("redirectionURL");
            red = nodeProperty.Value;
    
        if(red=="" )
        {
          Property nodeProperty2 = curNode.GetProperty("redirectionPage");
          red = umbraco.library.NiceUrl(Convert.ToInt32(nodeProperty2.Value));
        }
             Response.Redirect(red);
    
        }
    
    </script>
    

    error

    Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:

    Line 14:
    Line 15: Property nodeProperty = curNode.GetProperty("redirectionURL"); Line 16: red = nodeProperty.Value; Line 17:
    Line 18: if(red=="" )

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.] ASP.masterpagesredirectionpagemaster.Page_Load(Object sender, EventArgs e) in
    System.Web.UI.Control.OnLoad(EventArgs e) +108 System.Web.UI.Control.LoadRecursive() +67 System.Web.UI.Control.LoadRecursive() +164 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4497

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 08, 2017 @ 14:18
    Dennis Adolfi
    0

    Hi Burak.

    It sounds like 'nodeProperty might be null?

    Could you do a null check on nodeProperty before you call nodeProperty.Value?

  • burak 11 posts 92 karma points
    Jan 08, 2017 @ 15:50
    burak
    0

    Hi Dennis thx for your answer but ı try it not working

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 08, 2017 @ 19:34
    Dennis Adolfi
    0

    Have you made sure curNode is not null?

    Looking at https://our.umbraco.org/forum/developers/api-questions/46586-Get-current-node-as-IPublishedContent it looks like Node.GetCurrent doesn't work after Umbraco 4. Try replacing it with CurrentPage or with the UmbracoHelper.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 12, 2017 @ 07:14
    Dennis Adolfi
    0

    Hi burak.

    Did you figure this problem out? Could you share your solution?

    All the best!

  • burak 11 posts 92 karma points
    Jan 14, 2017 @ 17:57
    burak
    0

    no I m not

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 14, 2017 @ 19:23
    Dennis Adolfi
    0

    Sorry to hear that. Did you make sure curNode is not null? Since it seems Node.GetCurrent() is obsolete.

    Otherwise do you have Visual Studio? Could you try debugging to se which variable in your code is null. Without debugging it's more or less guessing..

  • burak 11 posts 92 karma points
    Jan 14, 2017 @ 20:09
    burak
    0

    I tried but could not it. can you share all code with me how can ı make curNode not null ??

  • Ferry Meidianto 36 posts 63 karma points
    Jan 15, 2017 @ 09:49
    Ferry Meidianto
    0

    Make sure that curNode is not null. Best to always check it before calling the property. And make sure that the docType of that node has redirectionURL property.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 16, 2017 @ 07:20
    Dennis Adolfi
    100

    Hi burak.

    To be honest it's been a wile since I worked with Umbraco 6 and WebForms, but here is a try:

    <%@ Import Namespace="Umbraco.Web" %>
    
    <script runat="server">protected void Page_Load(object sender, EventArgs e)
        {
            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var curNode = umbracoHelper.AssignedContentItem;
            string redirect = null;
    
            if (curNode != null && curNode.HasProperty("redirectionURL") && curNode.HasValue("redirectionURL"))
            {
                var redirectionUrl = curNode.GetProperty("redirectionURL");
                redirect = redirectionUrl.Value.ToString();
            }
    
            if (curNode != null && curNode.HasProperty("redirectionPage") && curNode.HasValue("redirectionPage") && string.IsNullOrEmpty(redirect))
            {
                var redirectionPage = curNode.GetProperty("redirectionPage");
                redirect = umbracoHelper.TypedContent(redirectionPage.Value.ToString()).Url;
            }
    
            if (!string.IsNullOrEmpty(redirect))
            {
                Response.Redirect(redirect);
            }
        }
    
    </script>
    

    Make sure that you dont miss <%@ Import Namespace="Umbraco.Web" %>, it's very important.

  • burak 11 posts 92 karma points
    Jan 16, 2017 @ 15:36
    burak
    1

    Hi Dennis ; Finally happened.. Thank you so much.. Thank you

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jan 16, 2017 @ 20:10
    Dennis Adolfi
    1

    Thank you Burak!

    I'm glad to hear that it worked out for you, happy to help!

    Have a great day!

Please Sign in or register to post replies

Write your reply to:

Draft