IIS InstallationThe column introduces how to use the IIS API to disable IP access
Free recommendations: IIS installation
This class is a simple package based on Microsoft.Web.Administration
:
PS: Microsoft.Web.Administration
Can be searched and installed through Nuget
.
public?class?IISAdministration { ????private?readonly?ServerManager?serverManager; ????public?IISAdministration() ????{ ????????serverManager?=?new?ServerManager(); ????} ????public?IEnumerable<WorkerProcess>?GetWorkerProcesses() ????{ ????????return?serverManager.WorkerProcesses; ????} ????public?IEnumerable<string>?GetSiteNames() ????{ ????????foreach?(var?item?in?GetWorkerProcesses()) ????????{ ????????????yield?return?item.AppPoolName; ????????} ????} ????public?ConfigurationElementCollection?GetIpSecurityCollection(string?site) ????{ ????????return?GetConfigurationElementCollection("system.webServer/security/ipSecurity",?site); ????} ????public?ConfigurationElementCollection?GetConfigurationElementCollection(string?sectionName,?string?site?=?"") ????{ ????????var?config?=?serverManager.GetApplicationHostConfiguration(); ????????ConfigurationSection?section; ????????if?(string.IsNullOrWhiteSpace(site)) ????????{ ????????????section?=?config.GetSection(sectionName); ????????} ????????else ????????{ ????????????section?=?config.GetSection(sectionName,?site); ????????} ????????return?section.GetCollection(); ????} ????public?void?CreateElement(ConfigurationElementCollection?section,?ConfigurationElement?element) ????{ ????????section.Add(element); ????????serverManager.CommitChanges(); ????} ????public?void?RemoveElement(ConfigurationElementCollection?section,?ConfigurationElement?element) ????{ ????????section.Remove(element); ????????serverManager.CommitChanges(); ????} ????public?bool?HasBlocked(string?siteName,?string?ip) ????{ ????????var?ipSecurityCollection?=?this.GetIpSecurityCollection(siteName); ????????for?(int?i?=?0;?i?<?ipSecurityCollection.Count;?i++) ????????{ ????????????var?element?=?ipSecurityCollection[i]; ????????????if?((string)element["ipAddress"]?==?ip) ????????????{ ????????????????return?true; ????????????} ????????} ????????return?false; ????} ????public?void?FreeIP(string?siteName,?string?ip) ????{ ????????if?(!HasBlocked(siteName,?ip)) ????????{ ????????????return; ????????} ????????var?ipSecurityCollection?=?this.GetIpSecurityCollection(siteName); ????????for?(int?i?=?0;?i?<?ipSecurityCollection.Count;?i++) ????????{ ????????????var?element?=?ipSecurityCollection[i]; ????????????if?((string)element["ipAddress"]?==?ip) ????????????{ ????????????????this.RemoveElement(ipSecurityCollection,?element); ????????????????break; ????????????} ????????} ????} ????public?void?BlockIP(string?siteName,?string?ip) ????{ ????????if?(HasBlocked(siteName,?ip)) ????????{ ????????????return; ????????} ????????var?ipSecurityCollection?=?this.GetIpSecurityCollection(siteName); ????????var?element?=?ipSecurityCollection.CreateElement("add"); ????????element["ipAddress"]?=?ip; ????????element["allowed"]?=?false; ????????ipSecurityCollection.Add(element); ????????serverManager.CommitChanges(); ????} }
Usage:
var?iisAdministration?=?new?IISAdministration(); iisAdministration.BlockIP("",?"192.0.0.1");
Note:
-
BlockIP
The first parameter is the site name. If it is an empty string, it will be used directly. Add to the IP mask under the root path ofIIS
. - This method will throw an exception and requires administrator privileges to execute.
The above is the detailed content of How to disable IP access using IIS API. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Use most text editors to open XML files; if you need a more intuitive tree display, you can use an XML editor, such as Oxygen XML Editor or XMLSpy; if you process XML data in a program, you need to use a programming language (such as Python) and XML libraries (such as xml.etree.ElementTree) to parse.

IIS is a web server software developed by Microsoft to host websites and applications. 1. Installing IIS can be done through the "Add Roles and Features" wizard in Windows. 2. Creating a website can be achieved through PowerShell scripts. 3. Configure URL rewrites can be implemented through web.config file to improve security and SEO. 4. Debugging can be done by checking IIS logs, permission settings and performance monitoring. 5. Optimizing IIS performance can be achieved by enabling compression, configuring caching and load balancing.

Bootstrap provides a simple guide to setting up navigation bars: Introducing the Bootstrap library to create navigation bar containers Add brand identity Create navigation links Add other elements (optional) Adjust styles (optional)

Reasons for IIS' popularity include its high performance, scalability, security and flexible management capabilities. 1) High performance and scalability With built-in performance monitoring tools and modular design, IIS can optimize and expand server capabilities in real time. 2) Security provides SSL/TLS support and URL authorization rules to protect website security. 3) Application pool ensures server stability by isolating different applications. 4) Management and monitoring simplifies server management through IISManager and PowerShell scripts.

Article Summary: Yii Framework is an efficient and flexible PHP framework for creating dynamic and scalable web applications. It is known for its high performance, lightweight and easy to use features. This article will provide a comprehensive tutorial on the Yii framework, covering everything from installation to configuration to development of applications. This guide is designed to help beginners and experienced developers take advantage of the power of Yii to build reliable and maintainable web solutions.

IIS is a web server software developed by Microsoft to host and manage websites and web applications. 1) Install IIS: Install on Windows server through Control Panel or Server Manager. 2) Create a website: Use PowerShell commands such as New-WebSite to create a new website. 3) Configure application pool: Set up an independent operating environment for different websites to improve security and stability. 4) Performance optimization: Adjust application pool settings and enable content compression to improve website performance. 5) Error debugging: Diagnose and resolve common errors by viewing IIS log files.

IIS is compatible with PHP and is implemented through the FastCGI module. 1.IIS supports PHP through the FastCGI module, making PHP run as an independent process. 2. Configuring IIS to run PHP requires defining the handler in the configuration file. 3. Basic usage includes enabling the FastCGI module and setting up PHP handlers. 4. Advanced usage can configure PHP environment variables and timeout settings. 5. Common errors include version incompatibility and configuration issues, which can be diagnosed through logs. 6. Performance optimization is recommended to adjust the PHP process pool size and enable OPcache.

IIS is Microsoft's web server software for hosting websites on Windows; WebHosting is storing website files on the server so that they can be accessed over the Internet. 1) IIS is simple to install and enabled through the control panel; 2) WebHosting selection requires stability, bandwidth, technical support and price to consider; 3) Shared Hosting is suitable for small websites, dedicated Hosting is suitable for websites with large traffic, and cloud Hosting provides high flexibility and scalability.
