Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Restrict Access to Internal IP

Posted on September 26, 2013October 26, 2015 By David Kittell

Many times we have sites that are public but have pages that should only be viewed by internal users.

Ideally the settings would be configured on the server level in IIS but if not possible for some reason this may help.

One key thing to note is this code will lock down access to a 10.x.x.x IP if you need to change that you need to add different options to the if (aIPAddress[0] != “10”) part of the code.

Example would be (aIPAddress[0] != “192” && aIPAddress[1] != “168”)

protected void Page_Load(object sender, EventArgs e)
	{
		string[] aIPAddress = GetIPAddress().Split('.');
        	if (aIPAddress[0] != "10")
	        {
        	    Response.Write("Not Authorized");
	            Response.Redirect("https://example.com/");
	        }
        else
        {
          //  Response.Write("Authorized");
        }
	}


protected string GetIPAddress()
    {
        System.Web.HttpContext context = System.Web.HttpContext.Current;

        string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (!string.IsNullOrEmpty(ipAddress))
        {
            string[] addresses = ipAddress.Split(',');
            if (addresses.Length != 0)
            {
                return addresses[0];
            }
        }

        return context.Request.ServerVariables["REMOTE_ADDR"];
    }
Originally Posted on September 26, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

C# ASPX Code CSharp

Post navigation

Previous post
Next post

Related Posts

Column Name Search

Posted on February 25, 2013February 8, 2016

An extension of Table/View Column Information In the event that you need to find a table that has a specific column name. SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE ‘%requestNumber%’ ORDER BY…

Read More

Clear Form Field Inputs

Posted on June 10, 2014October 26, 2015

ClearInputs(Page.Controls); private void ClearInputs(ControlCollection ctrls) { foreach (Control ctrl in ctrls) { if (ctrl is TextBox) ((TextBox)ctrl).Text = string.Empty; else if (ctrl is DropDownList) ((DropDownList)ctrl).ClearSelection(); ClearInputs(ctrl.Controls); } } Reference: http://stackoverflow.com/questions/4872364/clearing-all-fields-in-an-asp-net-form Originally Posted on June 10, 2014Last Updated on October 26, 2015 All information on this site is shared with the…

Read More

Ektron SQL – List All Users

Posted on July 19, 2013October 26, 2015

If you’re looking for more specific access lists look at Ektron – User Access List SELECT user_id ,[user_name] ,[first_name] ,[last_name] ,[email_address1] ,[email_address2] ,[email_address3] ,[address] ,[latitude] ,[longitude] FROM [users] u ORDER BY u.user_id SELECT utgt.usergroup_id, ug.usergroup_name, utgt.user_id, [user_name], [first_name], [last_name], [email_address1], [email_address2], [email_address3], [address], [latitude], [longitude] FROM [user_to_group_tbl] utgt INNER JOIN…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
©2025 David Kittell | WordPress Theme by SuperbThemes