我正在使用Windows身份验证,ASP.NET MVC5和C#以及SQL后端构建帮助台/资产跟踪Web应用程序。
在数据库中,我正在考虑通过Active Directory SID将支持票证和资产链接到用户,因为此值不会随时间而变化。他们的SID以及其他一些信息将进入一个名为“用户”的表中。
由于我是MVC的新手,在首次访问网站时,将用户的SID引入数据库的最有效方法是什么?我想在Global.asax中构建一些东西,但这似乎违背了MVC范式。
或者,是否有人建议采用更好的方法?
答案 0 :(得分:0)
这个想法非常普遍。
对于大多数网站(例如StackOverflow),您必须注册。您使用通用登录服务(StackExchange),并在首次登录时创建“配置文件”。
身份验证(也许授权)仍然通过原始来源(在您的案例中为AD)发生,而您真正需要的信息则保存在数据库中。
在AccountController.Login
操作中,您自己调用ActiveDirectory。
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(context, model.UserName))
{
// read back the user from database
// if non-existent: add it using a stored procedure or something like that
}
}