Hello,
I created a custom Profile provider as follows:
public class Profile : ProfileBase {
[SettingsAllowAn onymous(false)]
public Bio Bio { get; set; }
[SettingsAllowAn onymous(true)]
public Visitor Visitor { get; set; }
public static Profile Get() {
return Create(Membersh ip.GetUser().Us erName) as Profile;
}
public static Profile Get(string username) {
return Create(username ) as Profile;
}
}
Bio is a property available only for users that has signed on.
Visitor is a property available for all users.
Every time a user accesses a page I have:
Profile profile = Profile.Get(Use r.Identity.Name );
CultureInfo culture = profile.Visitor .Culture;
Of course if the user is accessing the page for the first time Visitor
is not defined and I get an error:
"Object reference not set to an instance of an object." on code line
2.
I could test if Visitor is null and if it is define a value for its
Culture.
But should I make this on the property itself? If yes, what is the
correct way to do this?
Thanks,
Miguel
I created a custom Profile provider as follows:
public class Profile : ProfileBase {
[SettingsAllowAn onymous(false)]
public Bio Bio { get; set; }
[SettingsAllowAn onymous(true)]
public Visitor Visitor { get; set; }
public static Profile Get() {
return Create(Membersh ip.GetUser().Us erName) as Profile;
}
public static Profile Get(string username) {
return Create(username ) as Profile;
}
}
Bio is a property available only for users that has signed on.
Visitor is a property available for all users.
Every time a user accesses a page I have:
Profile profile = Profile.Get(Use r.Identity.Name );
CultureInfo culture = profile.Visitor .Culture;
Of course if the user is accessing the page for the first time Visitor
is not defined and I get an error:
"Object reference not set to an instance of an object." on code line
2.
I could test if Visitor is null and if it is define a value for its
Culture.
But should I make this on the property itself? If yes, what is the
correct way to do this?
Thanks,
Miguel
Comment