2

I have a traditional ASP.NET WebForms application. I want to migrate it over to ASP.NET MVC 3. One of the central components of my WebForms application is a heavy use of the ProfileCommon instance that is automatically generated. Unfortunately, that object isn't available in ASP.NET MVC 3 applications.

I have created a ProfileCommon class using the advice found in the following thread: Implementing Profile Provider in ASP.NET MVC

My ProfileCommon class looks like the following:

public class ProfileCommon : ProfileBase
{
  public virtual string FirstName
  {
    get { return ((string)(this.GetPropertyValue("FirstName"))); }
    set { this.SetPropertyValue("FirstName", value); }
  }

  public virtual string LastName
  {
    get { return ((int)(this.GetPropertyValue("LastName"))); }
    set { this.SetPropertyValue("LastName", value); }
  }

  public static new ProfileCommon Create(string username) 
  { 
    return ProfileBase.Create(username) as ProfileCommon; 
  }

  public virtual ProfileCommon GetProfile(string username)
  {
    return Create(username) as ProfileCommon;
  }
}

In my web.config, I have:

<profile inherits="MyCompany.Namespace1.ProfileCommon" defaultProvider="CustomTableProfileProvider">
  <providers>
    <clear/>
    <add name="CustomTableProfileProvider" type="MyCompany.Namespace2.SqlTableProfileProvider" connectionStringName="MyDatabaseCS" table="MyTable" applicationName="MyApplication" />
  </providers>
</profile>

I then have the following code in my method in my controller that looks like this:

ProfileCommon userProfile = (ProfileCommon)(ProfileCommon.Create(username));
string greeting = "Hello " + userProfile.FirstName;

When the second line gets executed (the greeting), I get an exception. The exception says: System.Configuration.Provider.ProviderException: The CustomProviderData attribute is required on each provider property in the web.config file.

I do not understand what that means or what I need to do. I'm slightly confused because the individual in the previous aforementioned thread says everything worked. But it doesn't for me. Can someone please help me correct this error?

Thank you!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.