Copied to clipboard

Flag this post as spam?

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


  • Roald 6 posts 25 karma points
    Aug 11, 2014 @ 17:28
    Roald
    0

    Forbid direct url access to child nodes

    On our umbraco site we have a page that uses child nodes to dynamicaly fill the page, using RenderTemplate() with the children node Id's. It is now possible to visit these nodes directly, but we want to prevent this. What would be the best way to go about this? Thanks in advance. 

  • Mike Chambers 636 posts 1253 karma points c-trib
    Aug 11, 2014 @ 20:44
    Mike Chambers
    0

    You could use the URL rewrite module to redirect to the parent page if you have a pattern you can match on the URLs... Or have a macro/in line logic based on some boolean document parameter on your child pages to redirect to parent if the child page is hit? 

  • Allan Molsen Larsen 22 posts 192 karma points
    Aug 11, 2014 @ 21:56
    Allan Molsen Larsen
    0

    Hi Roald

    Another approach could be to set a different template for the child nodes, and let that template redirect to the parent page.

    If it's just one level up you can do something like:

    var parent = Model.Content.Parent;
    if (parent != null)
    {
       Response.RedirectPermanent(parent.Url);
    }
    

    Cheers,
    Allan

  • Roald 6 posts 25 karma points
    Aug 12, 2014 @ 09:47
    Roald
    0

    Thank you for the answers!

    I created a short URL check that redirects back to the parent node in case the Request.Url is the same as the URL of the node itself.

    Uri umbracoUrl = new Uri(umbraco.library.NiceUrlWithDomain(CurrentPage.Id)).TrimPathEndSlash();
    Uri requestUrl = Request.Url.TrimPathEndSlash();
    
    if (Uri.Equals(requestUrl, umbracoUrl))
    {
        Response.RedirectPermanent(CurrentPage.Parent.Url);
    }
    

    This seems to work perfectly. I am not sure if this will work in all cases, but for now I am satisfied.

Please Sign in or register to post replies

Write your reply to:

Draft