MVC3 应用程序中的多个 Active Directory 查找
我的 MVC 应用程序允许一部分用户在表中插入/编辑记录,并且由于我使用 Windows 身份验证,我“免费”获取他们的 samaccountnames,并且可以将它们插入到上述记录的“最后更新者”字段中。
我的应用程序中最重要(也是最常用)的视图之一将显示每页 50-100 条记录的列表,但我不想显示它们的 samaccountnames。我想要从 Active Directory 获取更用户友好的显示名称。
我在这里看到了几篇建议将 AD 链接到 SQL 的帖子,但这需要在 SQL 服务器上安装组件,但我不想这样做。相反,我正在考虑创建以下接口和派生类:
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.
}
我现在的问题是如何访问这些信息。我正在考虑使用 Ninject 的 ToSingleton,但我怀疑这可能是“Singleton Per Worker process”。所以也许缓存会是一个更好的地方。但是访问该对象的最佳方式是什么?具有静态属性的静态类,检查它是否已经在缓存中,否则初始化它,然后返回对象?
或者有没有更好的方法来解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终尝试了两种解决方案:
1
2
第二种方法明显更快,尤其是在缓存存储库的第一次调用之后。您还可以更好地控制缓存。第一个方法将保留在内存中,直到应用程序重新启动。
但我不确定这两种情况的最佳实践。
I tried 2 solutions eventually:
1
2
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.