First it is important to say that Profile
and Membership
are two completely different things, so much so that Profile
has its own library (System.Web.Profile).
That object Profile
is dynamic, so you set it the way you wanted in your file Web.config
containing:
It is important to say that this object must be fully assembled by its application, mainly regarding the attributes defined in its Web.config
.
For the logged-in user, this dynamically created object is accessible through the property HttpContext.Current.Profile
.
ProfileCommon
does not exist implemented for projects from Framework . NET 4.0. Microsoft at the time placed this discreetly in their migration manual (see "Converting Profile Object Code"). You can implement your own class ProfileCommon
, if you want, it will work as an envelope for the class ProfileBase
, sort of like this:
using System.Web;
using System.Web.Profile;
namespace MeuProjeto.Infrastructure
{
public class ProfileCommon : ProfileBase
{
public ProfileUserData UserData
{
get { return (ProfileUserData) GetPropertyValue("UserData"); }
}
public static ProfileCommon GetProfile()
{
return (ProfileCommon) HttpContext.Current.Profile;
}
public static ProfileCommon GetProfile(string userName)
{
return (ProfileCommon) Create(userName);
}
}
// Aqui coloquei mais umas coisas, como um exemplo de como posso
// estender esse objeto com coisas mais complexas, mas não que seja
// realmente necessário pra resposta.
[Serializable]
public class ProfileUserData
{
public string Endereco { get; set; }
public string Numero { get; set; }
public string Complemento { get; set; }
}
}
Notice that using like this:
ProfileCommon profile = Profile.GetProfile(usuario);
ProfileCommon
will come empty, because the method Create
of ProfileBase
will create the object dynamically with the basics of the basic, what can be seen here.
Therefore, to fill your object correctly, you would still have to change your envelope to bring the rest of the information:
public static ProfileCommon GetProfile(string userName)
{
var profileCommon = (ProfileCommon) Create(userName);
profileCommon.UserID = //Coloque aqui o UserId
profileCommon.Nome = // Coloque aqui o nome
profileCommon.Email = // Coloque aqui o e-mail
return profileCommon;
}
public Static Profilecommon Getprofile(string username) { } How do I retrieve database data?
– Marconi
@Marconi How does your application work with the bank? This is what you need to know.
– Leonel Sanches da Silva
I logged in with Memberships authentication. I tried to recover my profile and nothing through Httpcontext.Current.Profile
– Marconi
Obviously, because the object is empty. You ride it.
– Leonel Sanches da Silva
Profilecommon so if I can assign values to the target Profilecommon I can get its value on any page?
– Marconi
I understand your gypsy logic. When I Request this profile from Getprofile should I request asp_Membership and assign the values to profileCommon? This will make my profile accessible to all pages?
– Marconi
@Marconi Exactly. Logic is not my hehehehe. The component works like this.
– Leonel Sanches da Silva