How do I determine if the client is accessing the website through intranet or internet? RRS feed

  • Question

  • User1526116210 posted

    The situation is that I have a website on IIS 7.5 which accesses the internet through a proxy and some parts of the website will make a client side external request (images, YouTube videos etc.) which needs users to enter their proxy credentials if they are accessing the site through intranet.

    I would like to hide certain elements of the site if it is accessed through intranet and have it fully functional if accessed through internet.

    Internet requests to the site go through the proxy which is on the same network, thus it thinks that every request is an intranet request.

    So, how can I improve this helper to work in my situation if I know the proxy IP?

    @helper is_intranet() {
        string[] subIps = {"127", "10", "172", "192"};
        string strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
        IPAddress ipAddress = ipHostInfo.AddressList[0];
        var serverIP = ipAddress.ToString().Split('.');
        var clientIP  = HttpContext.Current.Request.UserHostAddress.Split('.');
        return ((serverIP[0] == clientIP[0]) && (subIps.Contains(serverIP[0])));

    Or, is there some way to determine whether the client is accessing the site through a proxy?

    Sunday, May 18, 2014 9:57 AM