Index > ASP.NET Web Applications > Unable to cast object of type 'ProfileCommon' t...

ASP.NET Web Applications:  Security , Profile Provider , Profile

Unable to cast object of type 'ProfileCommon' to type ‘ProfileCommon'

After converting an ASP.NET Web Application from a Web Site to a Web Application, the ProfileCommon class is no longer accessible in code.

Added on 4 Jul 2008

General Solutions:

Solution Summary:
Change syntax.
Solution Details:

You can access Profile properties, by using the following syntax:

Dim profile As System.Web.Profile.ProfileBase = CType(ProfileBase.Create(CreateUserWizard1.UserName), System.Web.Profile.ProfileBase)

Dim fName, lName, title As String

fName = CType(GetControl(CreateUserWizard1, "FirstName"), TextBox).Text
lName = 
CType(GetControl(CreateUserWizard1, "LastName"), TextBox).Text

profile.Item("FirstName") = fName
profile.Item.("LastName") = lName
Was this solution useful? Yes No Added on 4 Jul 2008

Solution Summary:
Create a custom profile class.
Solution Details:

Download the TableProfileProvider Samples at www.asp.net.

The main difference in getting it to work properly in a Web Project as opposed to a Web Site is that, for a Project, you may need to create a custom profile class to define your profile properties. (VB samples or C# samples).

Once the custom profile class is created, remember to remove the profile properties from the Web.Config file.  Otherwise, you will receive the following error:  “This profile property has already been defined.”

Using the TableProfileProvider with a custom profile class in which you define properties, will once again enable you to access properties in IntelliSense in your Web Project.

The syntax for accessing the profile properties will be as follows:

            If Request.IsAuthenticated Then
                Dim profs As ProfileUtility.UserProfile = ProfileUtility.UserProfile.GetUserProfile()
                litHeadInfo.Text = 
"Welcome " & profs.FirstName & " " & profs.LastName
End If
Was this solution useful? Yes No Added on 4 Jul 2008

Copyright 2017 © E-Centric, Inc. | Terms of Use