Asontu

Herman Scheele
.NET, C#, Sitecore developer and Data Science engineer @ theFactor.e.

profile for asontu at Stack Overflow, Q&A for professional and enthusiast programmers

Tech-blog about C#, Sitecore, T-SQL, Front-end, Python, Data Science and everything in between run by Herman Scheele

RSS Archive
28 December 2020

Admin-panel to whitelist IP's for identity server

One of our clients wanted to be sure that only white-listed IP’s can log into Sitecore to manage their site. We solved this by utilizing IIS’s IP Address and Domain Restrictions feature on the Sitecore Identity Server. That way adding or removing an IP only restarts the app-pool for the Identity Server, not the Sitecore instance. Annoyingly this has meant that every so often I have to log into the production server just to add an IP address to IIS, until I made this admin-page that let’s anyone with the developer role in Sitecore do this without all the hassle.

For this page to work, Microsoft.Web.Administration.dll needs to be available on the site. It’s available from NuGet. Also, as mentioned in the code, the App Pool needs read/write access to all files in %SystemRoot%\System32\inetsrv\config as well as the web.config of the site of which the white-listed IP’s need to be managed, i.e. the relevant Identity Server. Finally you need to put the IIS name of the site of interest as the constant siteOfInterest.

Update 2: I’ve tweaked the admin page to look better on mobile and accept IPv6 as it turns out IIS actually accepts IPv6 addresses on the back-end, the UI was just never updated for this.

Update 1: As I was deploying this I ran into another setting that needs tweaking. IIS needs to allow write delegation on the IP Address and Domain Restrictions feature for the relevant (Identity Server) site. Go to the root of IIS and open Feature Delegation:

Feature Delegation in IIS

Then pick Custom Site Delegation on the right (unless you wanna set this for all sites which I would advice against)

Custom Site Delegation button

Then select the Sitecore Identity Server up top, select IP Address and Domain Restrictions on the bottom and check if it says Read/Write. If not, click Read/Write on the right Actions panel.

Read/Write field

tags: Sitecore - C# - Back-end