Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Dec 08, 2011 @ 09:54
    dominik
    0

    Look if opened site is a root site

    Hello,

    in my own c# code i want to write an if statement.

    Is it possible to get the information if the url the user has tried to opend is a root path in umbraco?

    Can someone please help?

    Thanks

  • dominik 711 posts 733 karma points
    Dec 08, 2011 @ 14:56
    dominik
    0

    is there any way how i can get root path with umbraco.library from c# code?

  • gilad 185 posts 425 karma points
    Dec 09, 2011 @ 00:32
    gilad
    0

    i think you can use this : Request.ApplicationPath;

    take a look on this document : http://www.cambiaresearch.com/articles/53/how-do-i-get-paths-and-url-fragments-from-the-httprequest-object

  • dominik 711 posts 733 karma points
    Dec 09, 2011 @ 07:49
    dominik
    0

    Hi gilad,

    I think Request.ApplicationPath; will give me the request url path or? and not the root path of umbraco (i cant use static value here because it can be changed via content section "siteName").

    I need a script like:

    If URL (browser URL) = root.Node() than do something

  • Daniel Bardi 927 posts 2562 karma points
    Dec 14, 2011 @ 04:40
    Daniel Bardi
    0

    Check the current nodes NiceUrl  and compare to the root nodes NiceUrl.

    psuedo example:

    if (umbraco.NiceUrl(rootnode) == umbraco.NiceUrl(currentnode)) {
    ** do something **
    }

    or just compare the ids:

    if (rootnode.Id == currentnode.Id) {
     ** do something **
    }
  • dominik 711 posts 733 karma points
    Dec 14, 2011 @ 11:01
    dominik
    0

    Thanks Daniel,

    Will this also work if root node has a redirect and the user opens the redirected page via browser url?

    So the opened site is the redirected site from root node

    Thanks

  • Daniel Bardi 927 posts 2562 karma points
    Dec 14, 2011 @ 12:36
    Daniel Bardi
    0

    Don't think so.. if you browse directly to the "redireded" page, it won't have a handle to the node that would have redirected it normally.

    You could use the url to look up nodes that are redirecting to it.. if there is only one, then you have it.

    What method are you using to redirect?

  • dominik 711 posts 733 karma points
    Dec 14, 2011 @ 12:56
    dominik
    0

    Hi Daniel,

    I am using the "umbracoRedirect" method.

    The problem is that i dont want to use a fix path in my script because the sitename is dynamic and can change

    So the user open www.domain.com/en in browser and is forwarded to www.domain.com/en/home.aspx - there i have to look if it is a root redirect.

    Is this possible?

     

    Thanks

  • dominik 711 posts 733 karma points
    Jan 05, 2012 @ 12:30
    dominik
    0

    Hi Daniel,

    Any idea?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 05, 2012 @ 14:15
    Tom Fulton
    0

    You could try checking the HTTP_REFERER ServerVariable to see if it matches the "root" node's URL.

    Or...do you want it to fire if the user visits /en/home.aspx directly also?  Because then you could just use Daniel's code but compare against the node's parent also

  • dominik 711 posts 733 karma points
    Jan 05, 2012 @ 16:39
    dominik
    0

    Hi Tom,

    What i want to do is :

    Look if the opened URL is the root node or a redirect from the root node.

    But it should not be shown if url is www.domain.com/products/test.aspx

    Thanks for your help

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 05, 2012 @ 17:26
    Tom Fulton
    0

    Do you already know the ID of this "root node"?

    If so you could use Daniel's code but also compare the value of the umbracoRedirect

    int rootNodeUmbracoRedirectId;
    int.TryParse(rootnode.getProperty("umbracoRedirect").Value, out umbracoRedirectId);

    if
    (rootnode.Id== currentnode.Id || currentnode.id == rootNodeUmbracoRedirectId){
     
    **do something **
    }


  • dominik 711 posts 733 karma points
    Jan 05, 2012 @ 21:19
    dominik
    0

    hi tom

    i dont want to use a static root node. i want to get it dynamically. Is this possible? So rootnode.id should automatically be the root node

    If not how can i get it?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 05, 2012 @ 21:25
    Tom Fulton
    0

    What do you mean by root node, just that  it's a level 1 node?

    In that case you could test the current node's level, if it's 1 it's a root node right?  And if it's 2 you could check the umbracoRedirect on it's parent.

    Node currentNode = Node.GetCurrent();
    Node parentNode = new Node(currentNode.ParentId);
    if (currentNode.Level == 1 || (currentNode.Level == 2 && parentNode != null && parentNode.getProperty("umbracoRedirect").Value.ToString() == rootNode.Id.ToString())) {

    }

     

  • dominik 711 posts 733 karma points
    Jan 05, 2012 @ 21:34
    dominik
    0

    oh great thanks tom,

    Yes root is top level. There are two root nodes. My structure is like this

    - en (redirect to home)
       - home
       - Products
          - Test1
          - Test2
    - de (redirect to startseite)
       - startseite
       - Products
          - Test1
          - Test2

    And i want to check if the url the user has opend is the root.

    So it should return true if:
    domain.com - domain.com/en - domain.com/en/home.aspx
    or domain.com/de - domain.com/de/startseite.de

    is opened and false if

    domain.com/en/products/ is opend

    Thanks for all

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 05, 2012 @ 21:36
    Tom Fulton
    0

    Gotcha, I think the above would work then.  If current node's level is 1 then it's root.  Or if level is 2, then check the parent node's (level 1) umbracoRedirect and if it matches the current page, it's a "root".

  • dominik 711 posts 733 karma points
    Jan 05, 2012 @ 21:38
    dominik
    0

    thanks tom,

    i will try it on monday because tomorrow is a bank holiday in germany

    But one question will it know rootNode.ID? or where can i get it from?

    thanks for all

  • dominik 711 posts 733 karma points
    Jan 09, 2012 @ 08:51
    dominik
    0

    Hi Tom. If I try your script rootNode is not known. Can you please tell me how to get it?

    Thanks

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 09, 2012 @ 14:37
    Tom Fulton
    0

    Sorry, it should be currentNode.Id.ToString() instead of rootNode, since we are checking if the parent (level 1) has a redirect to the current page.

  • dominik 711 posts 733 karma points
    Jan 09, 2012 @ 14:51
    dominik
    0

    now its working. Thanks a lot

    Really great support!

Please Sign in or register to post replies

Write your reply to:

Draft