The name ' profile ' does not exist

Source: Internet
Author: User
Tags garbage collection shallow copy

In use

ProfileCommon profile = Profile.getprofile (myuser. ToString ());

To obtain profile information for a user, an error message appears: The name ' profile ' does is not exist in the present context

I searched it.

The profile property, developers use is actually a instance property to each. aspx page Class-the property name bei Ng "Profile". This is what allows developers to write profile.myfooproperty inside of a page, and things just magically.

Once you are in a static method though, there are no page instance and thus you can ' t make with the instance property cal Led "Profile".

To-get-to-a arbitrary profile from inside of the A static method try this instead:

ProfileCommon muprofile = (ProfileCommon) profilebase.create ("Username here", true);

This approach uses a static method on the base type of all asp.net profiles instances to fetch a profile and then cast it T o The Autogenerated profile type.

So, you need to use this sentence:

ProfileCommon muprofile = (ProfileCommon) profilebase.create ("Username here", true);

It's okay.

If you are using "asp.net Web application" instead of "web site," Note the following:

Visual Studio doesn ' t create the class on the fly when you ' re developing a ' asp.net Web application '.

There is a add-in here (http://www.gotdotnet.com/workspaces/workspace.aspx?id=406eefba-2dd9-4d80-a48c-b4f135df4127) . With this add-in can create the class. Just follow the instructions in the Readme file.

An article about profile:

/* from:http://www.cnblogs.com/boyxiao/archive/2010/03/02/1676414.html * ProfileBase base class discussion

Why is the blog named ProfileBase base class? Who is profilebase as the parent of the class?

In fact, this blog post will talk about three classes,

Also is the profile class, ProfileCommon class, ProfileBase class,

Where the profile class and the ProfileCommon class are derived from the ProfileBase class,

So the title of the article is named ProfileBase base class.

It says that both the profile class and the ProfileCommon class are derived from the ProfileBase class,

In fact, the profile class is essentially a ProfileCommon class (as explained below),

And ProfileCommon is inherited from the ProfileBase class,

It is said that the profile class and the ProfileCommon class are inherited from the ProfileBase base class,

After the introduction of the previous several Bowen Demo, more or less contact with the ProfileCommon class,

I think we almost know what this class is all about,

What about this ProfileCommon class,

Its general role is to operate on the profile of each particular user,

Previously used as follows

The first is to instantiate a dynamically generated class ProfileCommon
This class represents the profile of a user
ProfileCommon Usercommon =
Profile.getprofile (Ddlusername.selectedvalue);

Lbluser.text = usercommon.username;
Lbladdress.text = Usercommon. Address;
Lblconstellate.text = Usercommon. Constellation;

From this we can see that we first pass a GetProfile () method,

and passing in a username to get the ProfileCommon class,

Here you can see that the ProfileCommon class is instantiated for a particular user,

And the later use of ProfileCommon to access the property can also indicate that it is the operation of a single user profile,

At the same time, through the use of the profile class, we are generally aware that

To use profile This class, we have to login successfully before we can use (regardless of anonymity)

Because you have to tell profile who the current user of this class is,

So profile. Sava () is able to successfully save,

Otherwise it will not know who these user settings files are to be saved to,

But if you log in successfully,

The profile class gets the user name (successful login) on the current page to save the user settings file.

In this case, profile is for the user on the page where the current login is successful,

And ProfileCommon is for all the users,

But a ProfileCommon instance corresponds to only one user,

In terms of specificity, profile is a more specific class than ProfileCommon,

So it's not hard to understand why profile is essentially a ProfileCommon class,

But the above is not enough to fully prove that profile is a ProfileCommon class,

And since profile and ProfileCommon two classes are dynamically generated, MSDN can't be traced,

So it's more difficult to prove that

But you can use debugging to accomplish this task,

You can be in profile. [Property name] To set breakpoints so that you can view some of the profile's type information.

then start debugging, and when you run to the breakpoint,

since there is no screenshot here (the information is not visible as soon as the focus is lost),

so everyone had to try it on their own, but I copied some of the information back,

like

Profile = {ProfileCommon}

Base {System.Web.Profile.ProfileBase} = {ProfileCommon}

From here you can see that the type of profile is essentially a profilecommon,

And ProfileCommon is inherited from the ProfileBase class.

As for ProfileCommon inherited from ProfileBase class,

You check MSDN is also available, but the one in front of you is not good ...

Here's what MSDN says.

ASP.net uses the ProfileBase class to create a class for user profiles.

When you start an application that has a user profile enabled,

ASP.net creates a new class of type ProfileCommon,

The class inherits from the ProfileBase class.

The strongly typed accessors are added to the ProfileCommon class defined for each attribute in the profile configuration section.

Strongly typed accessors for the ProfileCommon class

Call the GetPropertyValue and setPropertyValue methods of the ProfileBase base class,

Used to retrieve and set the profile property values, respectively.

An instance of the ProfileCommon class is set to the value of the profile property of the ASP.net application.

It is not easy to say so much in the above, but I hope you can really understand the various mechanisms,

Instead of just using it.

So, the proof of the profile class is a ProfileCommon class,

And the ProfileCommon class is inherited from the ProfileBase class,

The following is the introduction of the base class ProfileBase class,

For this class, I think it's clear enough on MSDN,

I'm just going to copy some of the methods here.

You can check out more detailed information on your own.

from MSDN

The ProfileBase type exposes the following methods. Method

Create
has been overloaded. Creates an instance of a user profile.
Equals
Determines whether the specified object is equal to the current object. (inherits from Object.) )
Finalize
Allows object to attempt to free resources and perform other cleanup operations before garbage collection reclaims Object. (inherits from Object.) )
GetHashCode
Serves as a hash function for a specific type. (inherits from Object.) )
Getprofilegroup
Gets the attribute group identified by the group name.
GetPropertyValue
Gets the value of the configuration file property.
GetType
Gets the Type of the current instance. (inherits from Object.) )
Initialize
has been overloaded. Initializes the profile property values and information for the current user.
MemberwiseClone
Creates a shallow copy of the current Object. (inherits from Object.) )
Save
Updates the profile data source with the changed profile property values.

(Rewrite SettingsBase..::. Save () () (). )
setPropertyValue
Sets the value of the profile property.
Tostring
Returns a String that represents the current Object. (inherits from Object.) )

So now we should be able to understand the profile class, ProfileCommon class, ProfileBase class,

What exactly is the relationship between, you should know under what circumstances should use which class to complete the operation.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.