I see the following code everywhere on StackOverflow. Supposedly it gives you access to the Windows Firewall API and lets you view and set firewall rules, etc:
var firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
For example:
However, the type INetFwPolicy2
is not recognized by my ASP.NET 6 application, and I haven't been able to find what namespace it would be in.
Is the Windows Firewall API still available in ASP.NET 6? If not, how can I go about viewing Windows Firewall rules? This goes for ASP.NET Core 3.1 and 5 as well.