miy*_*ogL 2 forms-authentication asp.net-mvc-4
我正在尝试设置一个Intranet MVC应用程序,通过表单身份验证对我们公司的AD进行身份验证; 我们希望用户必须登录.发布到Login操作时,我收到以下异常:"要调用此方法,"Membership.Provider"属性必须是"ExtendedMembershipProvider"的实例." 还有其他人有这个问题吗?
Web.config文件:
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://example.domain.com/DC=example,DC=domain,DC=com"/>
</connectionStrings>
<appSettings>
<add key="enableSimpleMembership" value="false" />
</appSettings>
<system.web>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="45" slidingExpiration="false" protection="All"/>
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName"/>
</providers>
</membership>
Run Code Online (Sandbox Code Playgroud)
的AccountController:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
//The call to WebSecurity.Login is what throws
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
在VS2010中创建了一个MVC3站点,并使用ActiveDirectoryMembershipProvider.然后更改了MVC4 AccountController以使用旧的System.Web.Security而不是WebMatrix.WebData.WebSecurity.
从:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
至:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6418 次 |
| 最近记录: |