c# - Multiple Active Directory look-ups in MVC3 application -


my mvc application allows subset of users insert/edit records in table, , since i'm using windows authentication samaccountnames "for free" , can insert these in "last updated by" field in mentioned records.

one of important (and used) views in application display lists of 50-100 records per page, don't want display samaccountnames. want more user-friendly display names want active directory.

i've seen several posts here suggesting linking ad sql, requires installing components on sql server i'd rather not do. instead, thinking of creating following interface , derived class:

public interface iuserinformationstore {   userinformation findbysamaccountname(string samaccountname) }  public class activedirectorystore {   hashset<userinformation> _cache;    public userinformation findbysamaccountname(string samaccountname)   {     // samaccountname in _cache , if not found     // retrieve information ad directorysearcher.     // store information in _cache , return correct user. } 

my problem how access information. thinking of using ninject's tosingleton, suspect might "singleton per worker process". maybe cache better place it. best way of accessing object? static class static property checks if it's in cache already, initializes otherwise, , returns object?

or there better way of solving problem?

i tried 2 solutions eventually:

1

kernel.bind<iuserrepository>().to<activedirectoryuserrepository>().insingletonscope().withconstructorargument("rootpath", "ldap://dc=tessdata,dc=no");  public static mvchtmlstring getdisplaynamesingleton(this htmlhelper htmlhelper, string samaccountname) {   var userrepository = dependencyresolver.current.getservice<iuserrepository>();   return new mvchtmlstring(userrepository != null ? userrepository.findbyusername(samaccountname).displayname : "ukjent"); } 

2

kernel.bind<iuserrepository>().to<activedirectoryuserrepository>().withconstructorargument("rootpath", "ldap://dc=tessdata,dc=no");  public static mvchtmlstring getdisplayname(this htmlhelper htmlhelper, string samaccountname) {   if (httpruntime.cache["userrepository"] == null)   {     var newuserrepository = dependencyresolver.current.getservice<iuserrepository>();     httpruntime.cache.add("userrepository", newuserrepository, null, datetime.maxvalue,                                   timespan.fromminutes(20), cacheitempriority.default, null);   }   var userrepository = httpruntime.cache["userrepository"] iuserrepository;   return new mvchtmlstring(userrepository != null ? userrepository.findbyusername(samaccountname).displayname : "ukjent"); } 

the second method noticeably faster, after first call when repository cached. better control on caching too. first method stay in memory until application restarted.

i'm not sure best practice in either case though.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -