473,800 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using InvokeMember() to add blocked IP addresses to IIS

I am writing a small program that reads a text file filled with a large
number of IP addresses and attempts to add them to IIS so that they will be
blocked. For some reason, about one in every five or six ip addresses that I
attempt to add to IIS causes an System.Reflecti on.TargetInvoca tionException
to be thrown. Here is the code that adds the addresses:

static void SetIPSecurityPr operty(string metabasePath, string member,
string item)
{
try
{
if (("IPGrant" != member) && ("IPDeny" != member) &&
("DomainGran t" != member) && ("DomainDeny " != member))
{
Console.WriteLi ne(" Failed in SetIPSecurityPr operty; second
param must be one of IPGrant|IPDeny| DomainGrant|Dom ainDeny");
}
else
{
DirectoryEntry path = new DirectoryEntry( metabasePath);
path.RefreshCac he();
object ipsecObj = path.Invoke("Ge t", new string[] {
"IPSecurity " });
Type t = ipsecObj.GetTyp e();
Array data = (Array)t.Invoke Member(member, BindingFlags.
GetProperty, null, ipsecObj, null);
Console.WriteLi ne(item.ToStrin g());
bool exists = false;
foreach (object dataItem in data)
{
//Console.WriteLi ne(" {0}", dataItem.ToStri ng());
if (dataItem.ToStr ing().StartsWit h(item))
{
exists = true;
}
}

if (exists)
{
//Console.WriteLi ne(" {0} already exists in {1}", item,
member);
}
else
{
object[] newData = new object[data.Length + 1];
data.CopyTo(new Data, 0);
newData.SetValu e(item, data.Length);
//THE EXCEPTION IS THROWN FROM THE FOLLOWING CALL:
t.InvokeMember( member, BindingFlags.Se tProperty, null,
ipsecObj, new object[] { newData });
path.Invoke("Pu t", new object[] { "IPSecurity ", ipsecObj }
);
path.CommitChan ges();

path.RefreshCac he();
ipsecObj = path.Invoke("Ge t", new string[] { "IPSecurity "
});
data = (Array)t.Invoke Member(member, BindingFlags.
GetProperty, null, ipsecObj, null);
Console.WriteLi ne(item.ToStrin g() + " added. There are
now " + data.Length + " blocked IP entries.");
//Console.WriteLi ne(" New {0} =", member);
}
An ip address (and subnet) of "64.126.128 .0, 255.255.128.0" has no problem
being added, but when I try an ip address such as "64.126.192 .0, 255.255.128.
0" the InvokeMember (SetProperty) function throws and exception. If I open
up IIS and go to the properties of my web site and manually add "64.126.192 .0,
255.255.128.0" there is no problem. Anyone have any ideas? This is driving
me nuts.

Thanks in advance!

Mar 7 '08 #1
1 1874
Exact same prob here - works except with subnet added.

Please post if you find anything.
Jul 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4403
by: A. Gharbeia | last post by:
Greetings: It turned out that using COM objects from .NET C# isn't straight forward at all. Now, I have successfully used reflection to instantiate the object, and invoked the methods and properties through Type.InvokeMember, but... One property whose value I retrieve through : TImagingObject.InvokeMember("JPGData", BindingFlags.GetProperty, null, certificateImage, null);
0
1039
by: eirik hoem | last post by:
I have a problem using InvokeMember. I have a client application that loads a set of assemblies runtime. It creates instances of them and calls a method which I specify in a XML file. What I'm calling: t.InvokeMember(widget.InitMethod, BindingFlags.DeclaredOnly |BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, newWidget, widget.Parameters);
0
973
by: eirik hoem | last post by:
case-block was followed by a ; that's what you get for 13hrs straight ------------------------ I have a problem using InvokeMember. I have a client application that loads a set of assemblies runtime. It creates instances of them and calls a method which I specify in a XML file.
0
1313
by: Pat Ireland | last post by:
I continue to investigate issues with making explicit InvokeMember calls (necessary when dynamically loading classes). My quest lets me use a simple class to invoke another class's member method by normal means and by using the InvokeMember. By examining the underlying il code with ildasm, when attempting to pass by reference, the il code generates a box command so that a pointer to the actual data is passed. This is clearly seen with...
3
10173
by: Pat Ireland | last post by:
The following code shows what I am trying to do. The normal invocation of the CalcByRef produces the correct results, however, using the InvokeMember fails to correctly pass the single argument by reference. How can I correctly pass the short by ref through a InvokeMember. using System; using System.Reflection; namespace TestByRef { class DoByRef
3
6834
by: VB Programmer | last post by:
I have an ASPX page where I send out emails through my mail server mail.MyDomain.com. When I send emails to MyName@MyDomain.com it sends PERFECTLY. When I try sending an email to any other address (non-MyDomain.com address) I get the following error: The server rejected one or more recipient addresses. The server response was: 550 You must check your mail from this IP or SMTP Auth before sending to BSmith@Juno.com Here's the FULL...
2
1476
by: VB Programmer | last post by:
I'm encountering an error whenever I try to email people not in my domain. I get this error: The server rejected one or more recipient addresses. The server response was: 550 You must check your mail from this IP or SMTP Auth before sending to jimmy@juno.com Here's the full error:
3
1885
by: Riku Kosonen | last post by:
Hi, We have some problems with sending mail with the SMTP service on IIS (Windows 2000). We use the ASP.NET platform and have an ASPX-page that sends different mail messages to about 1000 clients. After some tests we found out that in one test some messages didn't arrive at all to the recipient. All logs state that the operation went nicely (no errors, no bad mail in the mailroot, etc.). We suspect that the target mail server (all...
14
8372
by: Warren Tang | last post by:
Hi I am using the mail function to send a mail like this: $b = mail("my_real_email_address@gmail.com", "Hello from PHP", "Hi, finally sent an email successfully"); But it failed. Could you guide me to get it work? Regards
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.