2011-02-13 10 views
5

estoy tratando de encontrar la manera de utilizar el ProfileProvider que es en este ejemplo: http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspxEntity framework Ejemplo de proveedor de servicios ... ¡Cómo inicializar y configurar ayuda!

Tengo los proveedores de pertenencia y el papel funcionando muy bien, tengo todo configurado exactamente como es en el ejemplo.

A continuación se muestra la clase que estoy usando al igual que las clases de membresía y roles. Esto a su vez sería llamado por mi 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); 
    } 
} 

En el código anterior busque [¿Qué debo poner aquí ?!]. Esto es con lo que estoy teniendo un problema.

En los servicios de suscripción y el papel que también se inicializan como nulo pero defecto, así que ellos llaman ya sea: Membership.Provider o Role.Provider, pero en este caso no se pueden utilizar Profile.Provider ya que no existe, por lo que todo lo que consigo es un proveedor nulo

¿Qué es lo que estoy haciendo una buena práctica para usar una membresía de perfil?

+0

¿Utiliza algún Ioc? –

Respuesta

2

El proveedor de perfiles es en realidad un poco diferente al rol y a los proveedores de membresía. Normalmente se establece teclas de perfil en la configuración como ..

..

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

Todo lo que necesita hacer es implementar la clase abstracta y configurarlo para ser utilizado en la 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 tiene un gran tutorial sobre proveedor de perfil generif.

También puede echar un vistazo a la fuente de conector mysql para .net ya que tiene un proveedor personalizado.

Existe también http://www.codeproject.com/KB/aspnet/AspNetEFProviders.aspx?display=Print

Así, en pocas palabras el proveedor de perfil es el único que no te gustan los proveedores de pertenencia y el papel.

Cuestiones relacionadas