/// Frank Hagen: Professional Web Developer, C# User, Reformed Über-geek RSS 2.0
# Thursday, January 04, 2007

This was MUCH easier to accomplish than ADSI info gathering.  Code is below:

    public bool IsMemberOf(string szGroupName)
    {
        System.Security.Principal.WindowsPrincipal user =
            (System.Security.Principal.WindowsPrincipal)HttpContext.Current.User;
        bool bVal = user.IsInRole(szGroupName);
        return (bVal);
    }
Thursday, January 04, 2007 9:31:06 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.NET

I don't usually like to post about other peoples' posts, but Coding Horror frequently causes exception.  If you're not reading it yet, but are me, then there must be something wrong with you!  Today Jeff posted another great article on two books I've never heard of:  The Secret Guide to Compters and CODE, both about the glorious life of the computer.  The first compares the computer experience to drugs and sex:

Computers are like drugs: you begin by spending just a little on them but soon get so excited by the experience - and so hooked - that you wind up spending more and more to feed your habit.

And

The computer will fascinate you. It'll seduce you to spend more time with it. You'll fall in love with it. You'll start buying it presents:  exotic foods (expensive programs to munch on), new clothes (a pretty little cloth cover to keep dust off), and expensive jewels (a printer and extra disks).

Sex or marriage, you decide.  Anyway Jeff Atwood does a much better write-up than I, so read his article.  I may have to get these books...

And his previous article on PC Clocks was geek chic for me too.

Thursday, January 04, 2007 9:07:33 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Blog | Life
# Tuesday, January 02, 2007

In the spirit of Me-Too:

Here are my results of the Super-Hero and -Villian likeness quizes.  What do you think?  And who are you?


My results:
You are Spider-Man
Spider-Man
75%
Green Lantern
60%
Robin
57%
Hulk
55%
Superman
50%
The Flash
45%
Iron Man
45%
Batman
40%
Supergirl
40%
Catwoman
20%
Wonder Woman
15%
You are intelligent, witty,
a bit geeky and have great
power and responsibility.
Click here to take the Superhero Personality Test

My results:
You are Magneto
Magneto
69%
Dr. Doom
65%
Lex Luthor
63%
Apocalypse
63%
The Joker
55%
Green Goblin
54%
Mr. Freeze
43%
Kingpin
40%
Riddler
37%
Dark Phoenix
29%
Catwoman
27%
Juggernaut
26%
Mystique
26%
Poison Ivy
23%
Two-Face
22%
Venom
20%
You fear the persecution of those that are different or underprivileged so much that you are willing to fight and hurt others for your cause.
Click here to take the Supervillain Personality Quiz
Tuesday, January 02, 2007 9:00:59 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Blog
# Monday, January 01, 2007

Wishing you good fortune for the coming year significantly labeled 2007.  Oops, that's pretty much an arbitrarily selected value too.

Monday, January 01, 2007 9:31:24 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Life
# Friday, December 22, 2006

In Intranet applications, it is often critical to know who your user is.  NTLM and .NET give you the ability to get the login name, which is a great identifier, but tells you nothing about them.  You get this by using:

HttpContext.Current.User.Identity.Name

though typically that can be shortened to simply User.Identity.Name.  However, with LDAP calls you can get more information, but you need to know the LDAP address of the domain controller for AD.  One tool I found that helps is ldp.exe which is available with the Windows Support Tools from Microsoft (free!).  Just connect to the AD controller and it gives you the LDAP address you can use in your System.DirectoryServices calls.

The guts of it are this: 
Make a connection to the domain controller using an LDAP address:

        szADPath = String .Format( "LDAP://CN=Users,DC={0},DC=com" , szDomain);

        DirectoryEntry entry = new DirectoryEntry (szADPath);

Create a DirectorySearcher with filters and find the user you want:

        string_szUID = HttpContext.Current.User.Identity.Name;

 

        DirectorySearcher search = new DirectorySearcher(entry);

        search.Filter = String.Format("(SAMAccountName={0})", _szUID.Substring(_szUID.IndexOf("\\") + 1));

        search.PropertiesToLoad.Add("displayName");    // Full Name (Frank Hagen)

        search.PropertiesToLoad.Add("employeeid");     // EmplID   (123456)

        search.PropertiesToLoad.Add("givenname");      // First Name (Frank)

        search.PropertiesToLoad.Add("sn");             // Last Name  (Hagen)

        SearchResult result = search.FindOne();        // Execute filtered search

Then iterate through all of the properties returned:

        foreach(string key in result.Properties.PropertyNames)

That's really all there is to it. 

Of course the data available is dependant on the quality of data input by the Network Support group.  If they don't put anything useful in, your still stuck with nothing.  We are fortunate here and are taking the employee id and querying against other sources for additional data.

I am building a class for internal projects to use this.  When I have cleaned it up and optimized it properly, I will post it.  It was hard to find good resources online for this, surprisingly, although there were many 3rd party paid products available.  Maybe I should package it up and sell it too....

Friday, December 22, 2006 10:29:05 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.NET
# Friday, December 01, 2006

Note to self:

To get the details of svchost.exe, which frequently gets a very large footprint and shows nothing in taskmgr other than used memory, execute the following from commandline:

tasklist /svc

Still don't know how to get details on the details...

Friday, December 01, 2006 4:25:23 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
System

Inheritance is a good thing.  It offers a great way to simplify coding through rollup of repetitive tasks and common attributes.  It is one reason why OOP is superior to most other programming methods.  It's a beautiful thing.

It also offers great job security.  Nothing endears your successor more than trying to figure out properties that are inherited 5 levels up in the abstraction with NO commenting or clue where to look.  And don't even get me started on N-Tier programming when N > 5!  Solutions get a bit unwieldy with 8+ projects attached.

Friday, December 01, 2006 10:24:33 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.NET | Programming | Work

This morning, a coworker told our BA that she needed to help the user to see the light.  From the look on her face, I think she'd prefer to help the user move toward the light.

Friday, December 01, 2006 9:40:31 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Work
<%--
--%>
Statistics
Total Posts: 186
This Year: 0
This Month: 0
This Week: 0
Comments: 72
Locations of visitors to this page
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Frank W Hagen
Sign In
All Content © 2010, Frank W Hagen
Custom DasBlog theme based on 'Business' by Christoph De Baene