Copied to clipboard

Flag this post as spam?

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


  • Bob 38 posts 160 karma points
    Nov 22, 2016 @ 10:32
    Bob
    0

    Restrict umbraco site

    Hello

    Umbraco 7.2 with two sites in one Umbraco. No culture or hostname set on either site.

    I would like the first site accessible to the public but the second to be limited by IP address. How could i do this?

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Nov 22, 2016 @ 14:02
    Steve Morgan
    0

    If you have different master pages for each site you should just be able to put some logic in the top of the master template to check the IP and then redirect if it isn't in the whitelist.

    HTH

    Steve

  • Bob 38 posts 160 karma points
    Nov 22, 2016 @ 16:09
    Bob
    0

    Thanks, any examples I could follow? Sorry new with umbraco

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Nov 22, 2016 @ 18:01
    Steve Morgan
    100

    Hi,

    This isn't really an Umbraco "thing" - more c#. Remember anything you can do in Razor & C# you can do in a template. so this would work in your Master.

    @{
        Layout = null;
    
        // i've mixed up IP v4 and v6 here.. 
        string[] whiteListedIPs = { "31.66.58.123", "::1" };
        string userIP = HttpContext.Current.Request.UserHostAddress;
        if (!whiteListedIPs.Contains(userIP))
        {
            HttpContext.Current.Response.Redirect("http://www.google.co.uk/");
        }
    
    }
    
  • Bob 38 posts 160 karma points
    Nov 23, 2016 @ 07:40
    Bob
    0

    Ah I see!! I thought there was an "Umbraco" wat of doing things. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft