Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1447

Unable to cast object of type 'System.Web.Profile.DefaultProfile' to type 'WebApplication1.Profil... (no replies)

$
0
0
Hi .net experts who works with MySQLProvider,

trying to learn MySql Provider.at my first sample attempt.ı wanted to use ProfileProvider for MySql and I 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;varchar")]
public virtual string FirstName
{
get
{
return ((string)(this.GetPropertyValue("FirstName")));
}
set
{
this.SetPropertyValue("FirstName", value);
}
}

[CustomProviderData("LastName;varchar")]
public virtual string LastName
{
get
{
return ((string)(this.GetPropertyValue("LastName")));
}
set
{
this.SetPropertyValue("LastName", value);
}
}
}

}

if I changed this function in ProfileCommon to this:


public static ProfileCommon GetUserProfile(string username)
{
return Create(username) as ProfileCommon;
//return ((ProfileCommon)(Create(username)));
//return (ProfileCommon)Create(username);
}

Profile return always null. and doesnt give error.

ProfileCommon Profile = ProfileCommon.GetUserProfile("User1");

simply can we say MySqlProfileProvider is not much usefull ?

may you provide us a good example howto use Profile in aspnet WebApplication (not aspnet website) ?

simply,Im trying to get /set the profile properties of the user given by name (not logined user.wantto get/set profile details by username)

Viewing all articles
Browse latest Browse all 1447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>