Пример провайдера Entity Framework. Как выполнить инициализацию и настройку, пожалуйста, помогите! - PullRequest
5 голосов
/ 13 февраля 2011

Я пытаюсь понять, как использовать ProfileProvider, который находится в этом примере: http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspx

У меня отлично работают поставщики членства и ролей, все настроено так, как в примере.

Ниже приведен класс, который я использую так же, как классы членства и ролей. Это, в свою очередь, будет вызываться моим AccountController.

public class AccountProfileService : IProfileService
{
    private readonly EFProfileProvider _provider;

    public AccountProfileService() : this(null) {}

    public AccountProfileService(ProfileProvider provider)
    {
        _provider = (EFProfileProvider)(provider ?? [What do I put here?!]);
    }

    public void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties)
    {
        if (context == null) throw new ArgumentException("Value cannot be null or empty.", "context");
        if (properties == null) throw new ArgumentException("Value cannot be null or empty.", "properties");

        _provider.SetPropertyValues(context, properties);
    }
}

В приведенном выше коде ищите [Что мне сюда поставить ?!]. Это то, с чем у меня проблемы.

В службах членства и ролей они также инициализируются как нулевые, но они по умолчанию, поэтому они вызывают: Membership.Provider или Role.Provider, но в этом случае я не могу использовать Profile.Provider, поскольку он не существует, так что все, что я получаю, это нулевой поставщик.

Кроме того, чем я занимаюсь при использовании членства в профиле?

1 Ответ

2 голосов
/ 06 марта 2011

Поставщик профиля на самом деле немного отличается от поставщика роли и членства.Обычно вы задаете ключи профиля в конфигурации, такие как ..

..

<profile enabled="true"

defaultProvider="CustomProfileProvider">



<providers>

    <clear /> 
    <add

        name="CustomProfileProvider"

        type="Providers.CustomProfileProvider, Providers"

        ApplicationName="Test" />

</providers>



<properties>

    <add name="ZipCode" allowAnonymous="false" />

    <add name="Phone" allowAnonymous="false" />

</properties>

Все, что вам нужно сделать, это реализовать абстрактный класс и установить его так, чтобы он былиспользуется в web.config.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Profile;

namespace blahh.Web.Source
{
    class Class1 : ProfileProvider
    {
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();
        }

        public override int DeleteProfiles(string[] usernames)
        {
            throw new NotImplementedException();
        }

        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            throw new NotImplementedException();
        }

        public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            throw new NotImplementedException();
        }

        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            throw new NotImplementedException();
        }
    }
}

http://www.davidhayden.com/blog/dave/archive/2007/10/30/CreateCustomProfileProviderASPNET2UsingLINQToSQL.aspx имеет большое руководство по поставщику профилей generif.

Также вы можете взглянуть на источник коннектора mysql для.нет, так как у него есть собственный провайдер.

Существует также http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspx?display=Print

Итак, в двух словах, провайдер профиля - единственный, кого вы не делаете, как провайдеры членства и роли.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...