空间引用
using System.Text; using System.Reflection; using System.DirectoryServices; using System.Text.RegularExpressions; using System.Security.Principal;
using System.DirectoryServices.ActiveDirectory; using System.Security.AccessControl; ///
/// 拒绝访问限制,格式如:10.10.10.10或10.10.10.*(可带*号,值为:0-255)或10.10.10.10,255.255.255.0 ///
public static bool setIPGrant(string metabasePath, string item) {
ConfigIIS.SetGrantByDefault(metabasePath, \ return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 拒绝访问限制,格式如:10.10.10.*(可带*号,值为:min-max) ///
public static bool setIPGrant(string metabasePath, string item,int min,int max) {
ConfigIIS.SetGrantByDefault(metabasePath, \
return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 拒绝访问限制,格式如:10.10.10.10或10.10.10.*(可带*号,值为:0-255)或www.http://m.wodefanwen.com/ ///
public static bool setIPDeny(string metabasePath, string item) {
ConfigIIS.SetGrantByDefault(metabasePath, \ return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 拒绝访问限制,格式如:10.10.10.*(可带*号,值为:min-max) ///
public static bool setIPDeny(string metabasePath, string item,int min,int max) {
ConfigIIS.SetGrantByDefault(metabasePath, \ return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 授权访问限制,格式如:10.10.10.10或10.10.10.*(可带*号,值为:0-255)或10.10.10.10,255.255.255.0
///
public static bool setDomainGrant(string metabasePath, string item) {
ConfigIIS.SetGrantByDefault(metabasePath, \ return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 授权访问限制,格式如:10.10.10.*(可带*号,值为:min-max) ///
public static bool setDomainGrant(string metabasePath, string item,int min,int max) {
ConfigIIS.SetGrantByDefault(metabasePath, \
return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 授权访问限制,格式如:10.10.10.10或10.10.10.*(可带*号,值为:0-255)或www.http://m.wodefanwen.com/ ///
public static bool setDomainDeny(string metabasePath, string item) {
ConfigIIS.SetGrantByDefault(metabasePath, \ return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
/// 授权访问限制,格式如:10.10.10.*(可带*号,值为:min-max) ///
public static bool setDomainDeny(string metabasePath, string item,int min,int max) {
ConfigIIS.SetGrantByDefault(metabasePath, \
return ConfigIIS.SetIPSecurityProperty(metabasePath, \ }
///
///
public static void GrantByDefaultTrue(string metabasePath) {
ConfigIIS.SetGrantByDefault(metabasePath, \ ConfigIIS.SetGrantByDefault(metabasePath, \ }
///
///
public static void GrantByDefaultFalse(string metabasePath)
{
ConfigIIS.SetGrantByDefault(metabasePath, \ ConfigIIS.SetGrantByDefault(metabasePath, \ }
///
public static bool SetIPSecurityProperty(string metabasePath, string member, string item) {
mes = \
try {
if ((\!= member) && (\!= member) && (\!= member) && (\ {
ConfigIIS.mes += \在SetIPSecurityProperty():传参错误,该方法参数member应为 IPGrant|IPDeny|DomainGrant|DomainDeny \\n\ return false; } else {
List
DirectoryEntry path = new DirectoryEntry(metabasePath); path.RefreshCache();
object ipsecObj = path.Invoke(\ Type t = ipsecObj.GetType();
Array data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null);
bool exists = false;
for (int i = 0; i < list.Count; i++) {
exists = false;
foreach (object dataItem in data) {
if (dataItem.ToString().StartsWith(list[i])) {
ConfigIIS.mes += \在SetIPSecurityProperty(): 已经存在 \ exists = true; } } if (!exists) {
object[] newData = new object[data.Length + 1]; data.CopyTo(newData, 0);
newData.SetValue(list[i], data.Length);
t.InvokeMember(member, BindingFlags.SetProperty, null, ipsecObj, new object[] { newData });
path.Invoke(\ path.CommitChanges();
path.RefreshCache();
ipsecObj = path.Invoke(\
data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null); } }
return true; } }
catch (Exception ex) {
if (\
ConfigIIS.mes += \在SetIPSecurityProperty():目录不存在\ else
ConfigIIS.mes += \在SetIPSecurityProperty():出现以下异常: \\n\ return false; } }
///
public static bool SetIPSecurityProperty(string metabasePath, string member, string item,int min,int max) {
mes = \
try {
if ((\!= member) && (\!= member) && (\!= member) && (\ {
ConfigIIS.mes += \在SetIPSecurityProperty():传参错误,该方法参数member应为 IPGrant|IPDeny|DomainGrant|DomainDeny \\n\ return false; } else {
List
DirectoryEntry path = new DirectoryEntry(metabasePath); path.RefreshCache();
object ipsecObj = path.Invoke(\ Type t = ipsecObj.GetType();
Array data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null);
bool exists = false;
for (int i = 0; i < list.Count; i++) {
exists = false;
foreach (object dataItem in data) {
if (dataItem.ToString().StartsWith(list[i])) {
ConfigIIS.mes += \在SetIPSecurityProperty(): 已经存在 \ exists = true; } } if (!exists) {
object[] newData = new object[data.Length + 1]; data.CopyTo(newData, 0);
newData.SetValue(list[i], data.Length);
t.InvokeMember(member, BindingFlags.SetProperty, null, ipsecObj, new object[] { newData });
path.Invoke(\ path.CommitChanges();
path.RefreshCache();
ipsecObj = path.Invoke(\
data = (Array)t.InvokeMember(member, BindingFlags.GetProperty, null, ipsecObj, null); } }
return true; } }
catch (Exception ex) {
if (\
ConfigIIS.mes += \在SetIPSecurityProperty():目录不存在\ else
ConfigIIS.mes += \在SetIPSecurityProperty():出现以下异常: \\n\
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C# IIS IP限制访问在线全文阅读。
相关推荐: