我使用Visual Studio 2012,並試圖作爲消化,但出現錯誤:
To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
所以我發現那幾個變化應做默認的登錄表單上的VS2012與MVC 4和實體框架如下:對文件「AccountController.cs」
對「公衆的ActionResult登錄(LoginModel型號,串
RETURNURL)」
更改
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
爲
if (ModelState.IsValid && Membership.Provider.ValidateUser(model.UserName, model.Password))
對 「公衆的ActionResult註銷(您)」
更改
WebSecurity.Logout();
爲
FormsAuthentication.SignOut();
,並添加以下內容:FormsAuthentication.SetAuthCookie(model.UserName,假);
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && Membership.Provider.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
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);
}
謝謝Marc。今天早上我開了一槍,一切都很順利。謝謝你的幫助! – cmcginty 2009-05-22 15:51:56
如果我們使用AD進行成員身份驗證並使用aspnet_profile來存儲配置文件。如何創建和管理關係,即。用戶名。換句話說,asp.net如何根據AD的什麼屬性來生成UserId? – 2011-08-01 05:30:21