Question

I've run into a bit of a pickle here. I have a custom profile that I used in two applications in the same solution. The first was a web application that I built to import a custom set of user profiles and attributes from an old .net application into the .net membership membership, roles, profile tables. I built a profile common class that inherits from profilebase. Both applications have a copy of the same class within their namespaces.

using System;
using System.Web.Security;
using System.Web.Profile;
using System.Collections.Specialized;


namespace WebProject
{
    public class ProfileCommon : ProfileBase
    {
        public static ProfileCommon GetUserProfile(string username)
        {
            return Create(username) as ProfileCommon;
        }

        public static ProfileCommon GetUserProfile()
        {
            return Create(Membership.GetUser().UserName) as ProfileCommon;
        }

        [SettingsAllowAnonymous(false)]
        public string FirstName
        {
            get
            {
                return base["FirstName"] as string;
            }
            set
            {
                base["FirstName"] = value;
            }
        }

        [SettingsAllowAnonymous(false)]
        public string LastName
        {
            get
            {
                return base["LastName"] as string;
            }
            set
            {
                base["LastName"] = value;
            }
        }

        [SettingsAllowAnonymous(false)]
        public string Email
        {
            get
            {
                return base["Email"] as string;
            }
            set
            {
                base["Email"] = value;
            }
        }

        [SettingsAllowAnonymous(false)]
        public StringCollection Sites
        {
            get
            {
                return base["Sites"] as StringCollection;
            }

            set
            {
                base["Sites"] = value;
            }
        }
    }
}

My profile provider section in my web config file looks like this.

<profile defaultProvider="WebProjectProfileProvider" inherits="WebProject.ProfileCommon">
  <providers>
    <clear />
    <add name="WebProjectProfileProvider" applicationName="/" type="System.Web.Profile.SqlProfileProvider" connectionStringName="Test"/>
  </providers>
</profile>

If I use one application to perform the user import and another that uses the membership, roles and profiles that I created would this cause the "The settings property '' was not found." error? I can't seem to pinpoint where the error is being caused and some of the most common causes I've already checked. This is the first time I've used this feature in .net on such a large scale. Any help is greatly appreciated.

Thanks.

Was it helpful?

Solution

I found my problem. The issue was in the calling code. I had run into so many issues regarding the profile that I forgot to change the calling code back to the static method

ProfileCommon.GetUserProfile();

The other issues I had run into as well was declaring the profile's properties in the web config and declaring them in a profile common class. This was causing me to get flip flopping errors such as "the property has already been defined." and "The settings property '' was not found."

In short, declare the ProfileCommon proxy class within code and not in the web.config IF you are using a "Web Application" solution. Declare the properties in web.config if you are using a "web site" solution.

The best example I've come accross on the web was from this site.

ASP.NET Profiles in Web Application Projects

It describes how to use custom profiles in a nice concise summary and gives a full explanation of why this method is performed for web applications and why it's done differently for web sites. Hope this saves many head aches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top