Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Thursday, June 20, 2019

C# + Active Directory = Awesome!!


I have a need to review AD groups and local admin groups as part of the identity project -  to identity users who are having privileged access in AD or servers. I developed this tool to help with the quick search, detailed view, export, etc with UI.

Obviously this can be done with PowerShell, but I found there is limitation with PowerShell in regards to recursive lookup especially when dealing with foreign objects

As you can see below, there are different account type you can query, user, computer and group (with recursive option). You can also provide a different credential to query Active Directory as well as specifying a particular OU, LDAP filter and keyword doing the search.

  

The below UI provides the interface to query local groups in Windows machine. You can specify a single computer, computers in a particular OU or a text file containing a list of computers.
 

Wednesday, November 22, 2017

Proxy PAC Tester v.2.0

New version of Proxy PAC Tester that supports client IP address to be passed to some of the JS function that checks against client IP address.


#LoveCoding

Wednesday, October 25, 2017

Active Directory GUID

Active Directory GUID is stored as Byte array (Byte[]).

To convert from Byte[] to string:

string guid = new Guid(Byte[] Object).ToString()

To convert from string to Byte[]:

string guid = <string guid here>

Guid g = Guid.Parse(guid);
Byte[] gba = g.ToByteArray();

string result = "";
foreach(Byte b in gba){ result += @"\" + b.ToString("x2"); }

Friday, September 08, 2017

GUID String to Octect String

If you need to perform LDAP query against Active Directory with objectGUID as the filter, you need to convert the string representation of that GUID to octetstring.

For example, if the objectGUID string value is: ffe17244-4c77-48e7-9db7-69578be7e232
You need to convert it to: \44\72\e1\ff\77\4c\e7\48\9d\b7\69\57\8b\e7\e2\32

so then you can provide the LDAP filter with:
(objectGUID=\44\72\e1\ff\77\4c\e7\48\9d\b7\69\57\8b\e7\e2\32)

To do this by C#, use the following function:

        private string convertStringGuidToOctectString(string guid)
        {
            Guid g = Guid.Parse(guid);
            Byte[] gba = g.ToByteArray();

            string result = "";
            foreach (Byte b in gba)
            {
                result = result + @"\" + b.ToString("x2");
            }

            return result;
        }

Good luck!

Thursday, December 01, 2016

Proxy Enforcer

I developed this little utility while doing proxy migration project. This utility helps me to enforce the Windows proxy settings to IE.


You can add Proxy by clicking the "Add Proxy" button, which gives you the same configuration like Windows


Once your proxy setting is added to the list, highlight the proxy and click "Select Proxy" to enforce the selected proxy to your IE. The program will run on the TaskBar. 



Wednesday, March 16, 2016

.NET Executing Assembly Location

During coding, if you want to reference another file, such as configuration file, text file or XML file that is located on the same location where your binary/library is you can use the following:''

string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

Have fun coding :)

Monday, May 19, 2008

Flex and .NET Web Service Error Handling

I was doing this Flex project that consumes .NET Web Service and could not figure out how to catch SOAPException from .NET Web Service.

It turns out that Flex could not read any response from the Web Service that has HTTP response code other then 200. You will get the following error (fault) from the Web Service if Flex was getting the HTTP response code other then 200:

FaultCode:Server.Error.Request
faultString:'HTTP request error'
faultDetail:'Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error.

Which is annoying because there was not specific details about the error!!

The workaround is to force .NET to return with the response status 200 if the response status code either 500 or 300.

You do this by put the following code in your application global.asax

<%@ language="C#" %>protected void Application_EndRequest(object sender,EventArgs e)
{
if(Context.Response.StatusCode==500 Context.Response.StatusCode == 300)
{
Context.Response.StatusCode = 200;
}
}