要调用此方法,“Membership.Provider”属性必须是“ExtendedMembershipProvider”的实例

目前每当我尝试注册一个用户或login使用默认的成员服务内置到我的主机提供商DiscountASP ASP.Net MVC4我收到错误

为了调用这个方法,“Membership.Provider”属性必须是“ExtendedMembershipProvider”的一个实例。

这不会在本地发生。

这是我的InitializeSimpleMembershipAttribute.cs

 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute { private static SimpleMembershipInitializer _initializer; private static object _initializerLock = new object(); private static bool _isInitialized; public override void OnActionExecuting(ActionExecutingContext filterContext) { // Ensure ASP.NET Simple Membership is initialized only once per app start LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock); } private abstract class SimpleMembershipInitializer { protected SimpleMembershipInitializer() { Database.SetInitializer<UsersContext>(null); try { using (var context = new UsersContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); } } } } 

以下是错误的完整截图:

有谁知道我可以如何解决这个问题或知道一个文章,解决它?

尝试在<system.web>节点的web.config设置以下内容:

  <roleManager enabled="true" defaultProvider="SimpleRoleProvider"> <providers> <clear /> <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" /> </providers> </roleManager> <membership defaultProvider="SimpleMembershipProvider"> <providers> <clear /> <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" /> </providers> </membership> <sessionState mode="InProc" customProvider="DefaultSessionProvider"> <providers> <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /> </providers> </sessionState> 

听起来像SimpleMembership不会被识别,当你去使用它。

另外,值得一提的是, WebMatrix.webData库可以通过NuGet安装:

 PM> Install-Package Microsoft.AspNet.WebPages.WebData 

尝试更改AccountController.cs下的loginfunction

  // // POST: /Account/Login [AllowAnonymous] [HttpPost] public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); } 

以上步骤,但没有帮助。 什么帮助改变web.config:

  <dependentAssembly> <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.0.0.0" /> </dependentAssembly> 

我有同样的错误,但是对我来说是100%的参考。 我有困难让WebMatrix.WebSecurity多次工作…每次都是因为我没有使用MVC 4 Internet模板创build项目。

关键是引用和configuration默认在模板中工作,所以只需重新创build您的项目,它会没事的。

我的修复是:1.将我的项目备份到另一个文件夹。 2.检出所有文件3.以完全相同的名称创build一个新的MVC 4 Internet项目。 4.复制+粘贴(覆盖)原始项目。 5.添加任何缺less的引用,更改路由,.config设置/数据库连接。