一直出现的错误:
您必须先调用“WebSecurity.InitializeDatabaseConnection”方法,然后再调用"WebSecurity"类的任何其他方法。此调用应当放在站点根目录的 _AppStart.cshtml 文件中。
,TMD, 网上的答案都是一样,你抄我的,我抄你的。
说下网上的解决方法:
1、把 SimpleMembershipInitializer 移到Global里面去,
2、然后 在 application_start 中重新注册
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
本人实测 无效。下面是我的代码
// // POST: /Account/Register [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid && model.Consentclause) { // 尝试注册用户 try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); new SimpleRoleProvider().AddUsersToRoles(new string[1] { model.UserName }, new string[1] { "tourUser" }); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return View(model); }
求个大爷教教我。真是头发都抓完了
http://blog.csdn.net/leftfist/article/details/18770511
在controller上加这个
[InitializeSimpleMembership]
个人觉得写爱 application start里面应该也可以
试过,也改过 application_start,没用,不然就不会出来提问了