2011-02-13 5 views
5

Ben bu örnekte var ProfileProvider nasıl kullanılacağını anlamaya çalışıyorum: http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspxVarlık çerçevesi Profil Sağlayıcı örneği .. Nasıl başlatılır ve kurulur lütfen yardım edin!

Ben üyelik ve rol sağlayıcıları harika çalışıyor var, bunu örnekte olduğu tam olarak nasıl her şeyi kurulum var.

Aşağıda, üyelik ve rol sınıfları gibi kullandığım sınıf var. Bu da benim AccountController'ım tarafından çağrılacaktı.

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); 
    } 
} 

Yukarıdaki kodda [Buraya ne yazmalıyım ?!]. Bu benim bir sorunum var. bu yüzden elde ettiğin Membership.Provider veya Role.Provider ama yok bu durumda ben Profile.Provider kullanamazsınız: üyelik ve rol hizmetlerinin onlar da boş olarak başlatılır ancak bunlar ya çağrı böylece varsayılan olarak

bir null sağlayıcı.

Ayrıca profil üyeliği kullanmak için iyi bir uygulama yapıyorum nedir?

+0

Herhangi bir Ioc kullanıyor musunuz? –

cevap

2

Profil sağlayıcı aslında rol ve üyelik sağlayıcılarından biraz farklı. Genellikle aşağıdakiler gibi config profilli tuşları ayarlamak ..

..

Eğer soyut sınıf uygulamak ve web kullanılmak üzere ayarlanmıştır yapmanız gereken

<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> 

. yapılandırma.


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 profil sağlayıcısına büyük bir öğretici vardır.

Ayrıca, özel bir sağlayıcıya sahip olduğu için .net için mysql bağlayıcı kaynağına bakabilirsiniz.

profil sağlayıcı Eğer üyelik ve rol sağlayıcıları gibi yapmazsanız tek de kısaca Yani http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspx?display=Print

yoktur.