Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3998352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:30:53+00:00 2026-05-20T07:30:53+00:00

My MVC application allows a subset of users to insert/edit records in a table,

  • 0

My MVC application allows a subset of users to insert/edit records in a table, and since I’m using Windows authentication I get their samaccountnames “for free” and can insert these in a “Last Updated By” field in the mentioned records.

One of the most important (and frequently used) views in my application will display lists of 50-100 records per page, but I don’t want to display their samaccountnames. I want their more user-friendly display names that I want to get from Active Directory.

I’ve seen several posts here suggesting linking AD to SQL, but that requires installing components on the SQL server which I’d rather not do. Instead, I was thinking of creating the following interface and derived class:

public interface IUserInformationStore
{
  UserInformation FindBySamAccountName(string samAccountName)
}

public class ActiveDirectoryStore
{
  HashSet<UserInformation> _cache;

  public UserInformation FindBySamAccountName(string samAccountName)
  {
    // Look for samaccountname in _cache and if not found
    // retrieve information from AD with DirectorySearcher.
    // Store information in _cache and return correct user.
}

My problem now is how to access this information. I was thinking of using Ninject’s ToSingleton, but I suspect that might be “Singleton Per Worker process”. So maybe the Cache would be a better place for it. But what would be the best way of accessing the object? Static class with static property that checks if it’s in the Cache already, initializes it otherwise, and returns the object?

Or is there a completely better way of solving this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:30:54+00:00Added an answer on May 20, 2026 at 7:30 am

    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"] as IUserRepository;
      return new MvcHtmlString(userRepository != null ? userRepository.FindByUsername(samAccountName).DisplayName : "Ukjent");
    }
    

    The second method was noticeably faster, especially after the first call when the repository was cached. You get better control over caching too. The first method will stay in memory until the application is restarted.

    I’m not sure about best practice in either case though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an ASP.NET application that allows users to edit and insert data
I have written an ASP.NET MVC application that allows the user to specify their
I have a file upload function in my asp.net mvc application that allows users
Let's say I have a Spring MVC web application and it allows users to
I have an ASP.NET MVC application that allows the user to upload a file
I have an ASP.NET MVC application with a route that allows searching for stuff
I am working on an ASP.NET MVC project which allows users to construct arbitrarily
I just got started running UI tests against my ASP.NET MVC application using WatiN.
I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD
I'm new to Entity Framework. I've created a Multi Tier Application, in MVC, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.