Windows Login Page Restriction

| |

Sometimes you have to restrict the visitor of a page to a username, if you don’t want to take the time to build a database you can simply use the username on the domain.

In the code below make sure you replace “<DOMAIN>” with your companies domain

protected void Page_Load(object sender, EventArgs e)
	{
		System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;

		string sEmployee = p.Identity.Name.Replace("<DOMAIN>", "").ToLower();

		//Response.Write(sEmployee);

		switch (sEmployee)
		{
			default:
				Response.Redirect("http://www.kittell.net");
				break;
			case "dkittell":
			case "testuser1":
			case "testuser2":
				break;
		}

	}
Originally Posted on August 19, 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.