Home
%3CLINGO-SUB%20id%3D%22lingo-sub-287871%22%20slang%3D%22en-US%22%3EHow%20to%20programmatically%20determine%20if%20a%20user%20is%20authorized%20in%20an%20IIS%20Website%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287871%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Sep%2005%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20A%20customer%20had%20a%20unique%20need%20of%20verifying%20authorized%20users%20against%20a%20website%20that%20runs%20on%20IIS.%20The%20code%20is%20short%20and%20simple%20if%20you%20know%20what%20component%20and%20method(s)%20to%20invoke.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3Eusing%20System%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eusing%20System.Collections.Generic%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eusing%20System.Linq%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eusing%20System.Text%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eusing%20System.Threading.Tasks%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eusing%20Microsoft.Web.Management.Server%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Enamespace%20ConsoleApp1%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eclass%20Program%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estatic%20void%20Main(string%5B%5D%20args)%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estring%20message%20%3D%20null%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estring%20isUserFound%20%3D%20%22No%22%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estring%20sprovider%20%3D%20null%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Estring%20userName%20%3D%20%22john.doe%22%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EManagementAuthorizationInfoCollection%20authorizedCollection%20%3D%20ManagementAuthorization.GetAuthorizedUsers(%22Default%20Web%20Site%22%2C%20true%2C%200%2C%2010)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Esprovider%20%3D%20%22Provider%3A%20%22%20%2B%20ManagementAuthorization.Provider%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22%7B0%7D%22%2C%20sprovider)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%2F%2F%20Search%20the%20returned%20collection.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eforeach%20(ManagementAuthorizationInfo%20authorizedInfo%20in%20authorizedCollection)%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%2F%2F%20Check%20to%20see%20if%20the%20user%20is%20already%20in%20the%20allowed%20users%20collection.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eif%20(userName.Equals(authorizedInfo.Name))%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EisUserFound%20%3D%20%22yes%22%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22Does%20John.doe%20exist%3F%20%7B0%7D%22%2CisUserFound)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22done%20calling%20Microsoft.Web.Management.dll.%20Hit%20any%20key%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.ReadLine()%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-287871%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Sep%2005%2C%202018%20A%20customer%20had%20a%20unique%20need%20of%20verifying%20authorized%20users%20against%20a%20website%20that%20runs%20on%20IIS.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-287871%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Easp%20net%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eauthorized%20user%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIIS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emicrosoft%20web%20management%20dll%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eprogramatically%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Euser%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Sep 05, 2018
A customer had a unique need of verifying authorized users against a website that runs on IIS. The code is short and simple if you know what component and method(s) to invoke.


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.Threading.Tasks;


using Microsoft.Web.Management.Server;


namespace ConsoleApp1


{


class Program


{


static void Main(string[] args)


{


string message = null;


string isUserFound = "No";


string sprovider = null;


string userName = "john.doe";


ManagementAuthorizationInfoCollection authorizedCollection = ManagementAuthorization.GetAuthorizedUsers("Default Web Site", true, 0, 10);


sprovider = "Provider: " + ManagementAuthorization.Provider;


Console.WriteLine("{0}", sprovider);


// Search the returned collection.


foreach (ManagementAuthorizationInfo authorizedInfo in authorizedCollection)


{


// Check to see if the user is already in the allowed users collection.


if (userName.Equals(authorizedInfo.Name))


{


isUserFound = "yes";


}


}


Console.WriteLine("Does John.doe exist? {0}",isUserFound);


Console.WriteLine("done calling Microsoft.Web.Management.dll. Hit any key");


Console.ReadLine();


}


}


}