我已经编写了一个使用Owin登录使用标准登录表单的网站。这工作正常。每个客户在其服务器上都有自己的站点版本,具有不同的web.config值,因此它的行为与每个客户想要的一样。
我现在已经被要求提供一个版本,该版本会自动通过检索用户ID来记录用户,然后使用此版本从本地Active Directory获取详细信息。
我有一个可以执行此操作的脚本,但我很难调用它。
我希望尽可能多地保存我的代码,以便继续使用User和UserManager对象。
我希望可以在Startup.Auth.cs脚本中修改某些内容,以便不使用LoginPath作为CookieAuthenticationOptions,而是指向我的Active Directory脚本。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
不幸的是,使用Active Directory脚本的路径替换LoginPath会导致无限循环,导致查询字符串对于浏览器错误而言太长。
我已将IIS设置为: 匿名身份验证:已禁用,ASP.Net模拟:已启用,表单身份验证:已禁用,Windows身份验证:已启用
过去5天我一直坚持这一点,所以任何帮助都会非常感激。谢谢。
答案 0 :(得分:1)
只需创建自己的提供程序,它将检查您的AD的用户名和密码,并将其添加到appBuilder中的CookieAuthenticationOptions对象。您的提供者类应继承CookieAuthenticationProvider并覆盖您需要的登录方法。在这里您可以找到可用方法列表