473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Profile. What am I doing wrong?

Hello,

I am using a custom Profile provider as follows:

public class Profile : ProfileBase {

[SettingsAllowAnonymous(false)]
public Bio Bio { get; set; }

[SettingsAllowAnonymous(true)]
public Visitor Visitor { get; set; }

public static Profile Get() {
return Create(Membership.GetUser().UserName) as Profile;
}
public static Profile Get(string username) {
return Create(username) as Profile;
}

}

Visitor is a class has follows:

[Serializable()]
public class Visitor {
public CultureInfo Culture { get; set; }
}

On my web page I am overriding InitializeCulture, by getting the value
of Visitor.Culture:

1 protected override void InitializeCulture() {
2 base.InitializeCulture();
3 CultureInfo culture = Profile.Get().Visitor.Culture;
4 if (culture != null) {
5 Thread.CurrentThread.CurrentCulture = culture;
6 Thread.CurrentThread.CurrentUICulture = culture;
7 }
8 }

Because of code line 3 I always get an error on my profile provider:

1 public static Profile Get() {
2 return Create(Membership.GetUser().UserName) as Profile;
3 }

The error is on line 2 and says:

"Object reference not set to an instance of an object. Use the new
keyword to create an object instance."

What am I doing wrong?

Thanks,

Miguel
Oct 9 '08 #1
1 1868
On Oct 9, 10:32*pm, shapper <mdmo...@gmail.comwrote:
Hello,

I am using a custom Profile provider as follows:

* public class Profile : ProfileBase {

* * [SettingsAllowAnonymous(false)]
* * public Bio Bio { get; set; }

* * [SettingsAllowAnonymous(true)]
* * public Visitor Visitor { get; set; }

* * public static Profile Get() {
* * * return Create(Membership.GetUser().UserName) as Profile;
* * }
* * public static Profile Get(string username) {
* * * return Create(username) as Profile;
* * }

* }

Visitor is a class has follows:

* [Serializable()]
* public class Visitor {
* * public CultureInfo Culture { get; set; }
* }

On my web page I am overriding InitializeCulture, by getting the value
of Visitor.Culture:

1 * * * *protected override void InitializeCulture() {
2 * * * * *base.InitializeCulture();
3 * * * * *CultureInfo culture = Profile.Get().Visitor.Culture;
4 * * * * *if (culture != null) {
5 * * * * * *Thread.CurrentThread.CurrentCulture = culture;
6 * * * * * *Thread.CurrentThread.CurrentUICulture = culture;
7 * * * * *}
8 * * * *}

Because of code line 3 I always get an error on my profile provider:

1 * * * *public static Profile Get() {
2 * * * * *return Create(Membership.GetUser().UserName) as Profile;
3 * * * *}

The error is on line 2 and says:

"Object reference not set to an instance of an object. Use the new
keyword to create an object instance."

What am I doing wrong?

Thanks,

Miguel
I changed my code to the following and debbuged it:

Profile profile = Profile.Get(User.Identity.Name);
CultureInfo culture = profile.Visitor.Culture;

Now profile is defined but Visitor is null ... So now I have the same
error, "Object reference not set to an instance of an object." on code
line 2.

The user is an anonymous user and it is the first time that accesses
the web site so it is normal that none of the profile properties have
been defined.

How should I prevent this error?

Thanks,

Miguel
Oct 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: a | last post by:
Q. Unable to get a Profile custom (object) collection to bind to GridView,etc (IList objects)? This is my first custom object so I may be doing something rather simple, wrong, or it may be...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
9
by: Kirk | last post by:
I have successfully, implemented a custom Membership Provider to a SQL 2000 table, however, I am having problems doing the same with a Profile Provider. As I understand it, the steps for both of...
3
by: shapper | last post by:
Hello, In my Page's VB.NET code I am changing the value of the Profile property NAME. Profile.Name = tbName.Text However, I need to change this property value from a class in my App_Code...
2
by: shapper | last post by:
Hello, I have an ASP.NET page and in its runtime code I am trying to get an user profile, change it and save it. It works if I use Profile, which is the profile for the current authenticated...
0
by: =?Utf-8?B?S3VtYXIgVGhpYWdhcmFqYW4=?= | last post by:
I am using a custom sql profile provider. I need to loop through the Profile properties and get their names and values. The Profile.PropertyValues collection at most times has a Count of 0....
1
by: vasilip | last post by:
I'm trying to insert large polygon data via sql statement. since the data was over 32k I had to use sqlj to insert my data. I made a class that inserts the data. ran sqlj, generated the .java...
0
by: shapper | last post by:
Hi, I want to access the profile from the current user. Shouldn't it be as simple as: Profile.PostalCode = "1000"; However, when I write Profile on my C# code it is not recognized. Do I...
5
by: Steven | last post by:
I have the following in my web.config: <system.web> <profile defaultProvider="MyASPSqlProfileProvider" enabled="true" > <properties> <add name="FirstName" defaultValue="" type="string"/> <add...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.