/// Frank Hagen: Professional Web Developer, C# User, Reformed Über-geek RSS 2.0
# 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
# Monday, November 27, 2006

This is the first book in a trilogy about the colonization of Mars.  The first book itself is enormous in scope, from the departure from Earth, the landing, building of settlements, commercialization, and finally Revolution.  Perhaps too large in scope.  The whole series was recommended to me by GP, whose judgment I respect.

Red Mars is the story of a handful of the "First Hundred" colonists on Mars.  They are the pioneers of the new frontier, braving the journey out, surviving planet-side and establishing the first settlement for permanent habitation.  We are treated to Love Triangles, political maneuvering, interpersonal conflict, and clique groups.  Surely some of my favorite themes.  And once the de facto leader of the First Hundred is murdered, we get political intrigue added too.  No investigation, just intrigue.

Technically, this was a brilliant work.  Narratively, not so much.  I found that I really didn't care about the characters and frequently lost track of what was going on.  I don't think it was that there were too many characters, because Red Storm Rising had more and was an incredible story.  Many times I would be reading a segment and have completely forgotten why they were doing some action.  It may be that as a dad of two very small ones, it was natural to fall asleep reading this book every night:  It was definitely a long read;  I purchased this book in July and only finished it this weekend.  My personal opinion is that this would have made a great prequel to an established series; the author tried to put way too much into this book causing it to be flat.  I am disappointed in this book, and despite owning the other two books, I am not sure I will read them. 

 

Monday, November 27, 2006 12:40:55 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Books
# Wednesday, November 22, 2006

When you are looking at someone else's code, at what point can you definitively know it is bad code?  I'm sure everyone has their metrics.  Here's mine and so simple too:

Server Timeouts

Yep, real simple.  Here's the thing:  Nothing else, in my mind, shows a greater lack of understanding of the basic architecture of a system than poorly set timeouts.  For instance.  while not a bad idea to adjust the timeout of the SQL connection to fit what you are doing, setting it to 1200 means you don't realize that it means seconds and you just told your application to wait 20 minutes before doing any damage control.  I don't know about you, but ANY application that makes me wait 20 minutes for anything (without showing me real progress) is broken; I am impatient after 20 seconds!  Another example:  setting an ASP.NET app to use a session timeout of 300 minutes means you don't care about your server at all.  Why not store user specific information (full DATASETS!) in memory for 5 hours after the user has left the page.  5 hours!

These are real examples of code I am working on today.  I don't care how elegant your architecture is, Server Timeout abuse has always been a very simple indicator of developer incompetance.  Oh, and it seems to be in direct proportion of scale too.  I have actually seen an ASP session set to 3000000.  Yes 3 MILLION minutes.  That is 50,000 hours.  5 years, 8 months, 14 days, 13+ hours.  Yeah, that'll work.  I was not well loved because I wouldn't allow crap like that to run on my servers.

BTW, 3M minutes was by the same coder who thought LastName is a good primary key on a DB.  And when that didn't work, how about a composite key on LastName, FirstName.  Yep, World Class programmer.

Wednesday, November 22, 2006 3:03:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Programming | Rant

Congrats to GP for his new change of status.  Sorry I missed the party, I bet it was memorable.

Wednesday, November 22, 2006 12:30:01 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Life
<%--
--%>
Statistics
Total Posts: 189
This Year: 2
This Month: 0
This Week: 0
Comments: 74
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 2012
Frank W Hagen
Sign In
All Content © 2012, Frank W Hagen
Custom DasBlog theme based on 'Business' by Christoph De Baene