Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Block Specific IP Addresses from Accessing a Web Role

Updated: October 24, 2014

You can restrict an Azure web role access to a set of specified IP addresses by modifying your IIS web.config file and creating a command file which unlocks the ipSecurity section of the ApplicationHost.config file.

First, create a command file that runs when your role starts which unlocks the ipSecurity section of the ApplicationHost.config file. Create a new folder at the root level of your web role called startup and, within this folder, create a batch file called startup.cmd. Set the properties of this file to Copy Always to ensure that it will be deployed.

Add the following code to the startup.cmd file:

%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity

Next, open the ServiceDefinition.csdef file in your web role project and add the following element:

   <Task commandLine=”startup\startup.cmd” executionContext=”elevated” />

This causes the startup.cmd batch file to be run every time the web role is initialized, ensuring that the required ipSecurity section is unlocked.

Finally, modify the system.webServer section your web role’s web.config file to add a list of IP addresses that are granted access, as shown in the following example:

  < security>
    <!—Unlisted IP addresses are denied access–>
    <ipSecurity allowUnlisted=”false”>
      <!—The following IP addresses are granted access–>
      <add allowed=”true” ipAddress=”” subnetMask=”″ />
      <add allowed=”true” ipAddress=”″ subnetMask=”″ />

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft