Hi again,
trying to learn MySql Provider.at my first sample attempt.ı wanted to use ProfileProvider for MySql and ı thought my ProfileCommon class written for SQL Server should work for MySql Provider too.But t didnt and dont know why.
ProfileCommon Profile = ProfileCommon.GetUserProfile("User1"); this line raises error
Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'WebApplication1.ProfileCommon'.
hcetiner
Member
579 Points
465 Posts
Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'WebApplication1.Profil...
May 14, 2012 07:17 PM|LINK
Hi again,
trying to learn MySql Provider.at my first sample attempt.ı wanted to use ProfileProvider for MySql and ı thought my ProfileCommon class written for SQL Server should work for MySql Provider too.But t didnt and dont know why.
ProfileCommon Profile = ProfileCommon.GetUserProfile("User1"); this line raises error
Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'WebApplication1.ProfileCommon'.
this is my web.config :
...... <system.web> <authentication mode="Forms" /> <compilation debug="true" targetFramework="4.0" /> <membership defaultProvider="MySQLMembershipProvider"> <providers> <clear/> <add name="MySQLMembershipProvider" autogenerateschema="true" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" /> </providers> </membership> <profile defaultProvider="MySQLProfileProvider"> <providers> <clear/> <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ConnectionString1" applicationName="/" /> </providers> </profile> <roleManager enabled="true" defaultProvider="MySQLRoleProvider"> <providers> <clear/> <add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ConnectionString1" applicationName="/" /> </providers> </roleManager> </system.web> </configuration>and this is my ProfileCommon Class :
namespace WebApplication1 { public class ProfileCommon : ProfileBase { public static ProfileCommon GetProfile() { return Create(HttpContext.Current.Request.IsAuthenticated ? HttpContext.Current.User.Identity.Name : HttpContext.Current.Request.AnonymousID, HttpContext.Current.Request.IsAuthenticated) as ProfileCommon; } public static ProfileCommon GetUserProfile(string username) { return (ProfileCommon)Create(username); } public static ProfileCommon GetUserProfile() { return Create(Membership.GetUser().UserName) as ProfileCommon; } [CustomProviderData("FirstName;nvarchar")] public virtual string FirstName { get { return ((string)(this.GetPropertyValue("FirstName"))); } set { this.SetPropertyValue("FirstName", value); } } [CustomProviderData("LastName;nvarchar")] public virtual string LastName { get { return ((string)(this.GetPropertyValue("LastName"))); } set { this.SetPropertyValue("LastName", value); } } } }