本文介绍了要调用该方法," Membership.Provider"属性必须是&QUOT实例; ExtendedMembershipProvider"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently whenever I try to register a user or login using the default membership services built into ASP.Net MVC4 on my host provider DiscountASP I receive the error

要调用这个方法,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);
            }
        }
    }
}

下面是错误的全屏截图:

Here is a full screenshot of the error:

有谁知道我可以解决这一问题或知道解决它的文章呢?

Does anyone know how I can fix this or know an article that addresses it?

推荐答案

尝试设置在的web.config &LT内采取后续行动;的System.Web&GT; 节点:

    <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无法识别。

Sounds like SimpleMembership isn't recognized when you go to use it.

另外,它可能是值得包括该<$c$c>WebMatrix.webData图书馆可以通过的NuGet安装:

Also, it may be worth including, the WebMatrix.webData library can be installed via NuGet:

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

这篇关于要调用该方法,&QUOT; Membership.Provider&QUOT;属性必须是&QUOT实例; ExtendedMembershipProvider&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:06