|
Very good job, but please pay attention that in some contexts, on IIS for instance, the table names are case-sensitive, so if you use aspnet_Profile in the tool, you must create the table with CREATE TABLE aspnet_Profile, rather than CREATE TABLE aspnet_profile. It takes MUCH less time than to position the trace afterwards, and to discover why the contents of a basket does not evolve as it should.
|
|
|
|
|
normally mysql and asp.net works perfectly. it saves profiles and bring back the values like I wrote it. but sometime this provider replaces the profile values with each other users. I could not solve this so far. its been more then 2 years I am using mysql profile provider it happens almost 2 times in 3 or 6 months. it may about IIS application pool or something like that I am not sure.
has anyone else have this kind of problem ? and has any solution to this issue ?
|
|
|
|
|
Hello mascix, are your users present on several applications ?
|
|
|
|
|
no there is one application.
|
|
|
|
|
Hello Sir,
I have using Profiler in my web application.my application give me a error : error occured in connection establinshing sql server plz give reply its urgent
Lav
lav naphade
|
|
|
|
|
Hello, did you verify you connection string ?
|
|
|
|
|
Hi, Edacio,
Great code and great functionality. I almost have it all implemented after reading through the comments but I have a question.
Upon completing the insert of data and performing Profile.Save() after using Profile.FieldName = TEXTBOX.TEXT, I get the following output in the db:
PropertyName: FirstName:S :SmackTalk:S :Location:S :LastName:S :
PropertyStringsValue: NULL
-- Any ideas?
Also, if I go back in attempt to do another request, it states that a key already exists and won't let me UPDATE my record once entered...
|
|
|
|
|
Here is a pretty useful product that doesn't force you to be tied to any specific database for your provider code. Works perfectly with MySQL 4.1 and 5.x.
21 Providers for ASP.NET
Thanks!
-Alex
|
|
|
|
|
Hello all, just wanted to give a big thanks to the author of this code and the other helpful posters on this forum... It took me a while to get everything working and some parts were a little hard to piece together, but here is what I did to get everything working. **I am not using the RoleProvider, so I am not sure if that works with this setup...
1. Copy the code into the AppCode folder of my project.
2. Create the database using pc.huff's creation strings:
CREATE TABLE aspnet_profile (<br />
PKID varchar(36) collate latin1_general_ci NOT NULL default '',<br />
LastUpdatedDate datetime default NULL,<br />
PropertyNames text default NULL,<br />
PropertyValuesString text default NULL<br />
);<br />
<br />
<br />
CREATE TABLE aspnet_applications (<br />
ApplicationName text default NULL,<br />
ApplicationId int(11) default NULL,<br />
Description text default NULL,<br />
PropertyValuesString text default NULL,<br />
PRIMARY KEY (`ApplicationId`)<br />
);<br />
<br />
CREATE TABLE `users` (<br />
PKID varchar(36) NOT NULL default '',<br />
Username varchar(255) NOT NULL default '',<br />
ApplicationName varchar(100) NOT NULL default '' ,<br />
Email varchar(100) NOT NULL default '',<br />
`Comment` varchar(255) default NULL,<br />
`Password` varchar(128) NOT NULL default '',<br />
PasswordQuestion varchar(255) default NULL,<br />
PasswordAnswer varchar(255) default NULL,<br />
IsApproved tinyint(1) default NULL,<br />
LastActivityDate datetime default NULL,<br />
LastLoginDate datetime default NULL,<br />
LastPasswordChangedDate datetime default NULL,<br />
CreationDate datetime default NULL,<br />
IsOnLine tinyint(1) default NULL,<br />
IsLockedOut tinyint(1) default NULL,<br />
LastLockedOutDate datetime default NULL,<br />
FailedPasswordAttemptCount int(11) default NULL,<br />
FailedPasswordAttemptWindowStart datetime default NULL,<br />
FailedPasswordAnswerAttemptCount int(11) default NULL,<br />
FailedPasswordAnswerAttemptWindowStart datetime default NULL,<br />
ApplicationId bigint(20) default NULL,<br />
MobileAlias text NULL,<br />
IsAnonymous varchar(5) NULL default NULL,<br />
PRIMARY KEY (`PKID`)<br />
);
3. Make drobol's changes (starting at line 410 of the MySQLProfileProvider)
410 cmd = new MySqlCommand("SELECT PKID FROM aspnet_Profile WHERE PKID = '" + userId + "'", conn, trans);<br />
411 object result = cmd.ExecuteScalar();<br />
412 if (result != null ) {<br />
413 string userid1 = result.ToString();<br />
414 string userid2 = userId.ToString();<br />
415 if (userid1 == userid2){<br />
416 cmd = new MySqlCommand("UPDATE aspnet_Profile SET PropertyNames ='" + names + "', PropertyValuesString ='" + values + "', LastUpdatedDate ='" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "' WHERE PKID ='" + userId + "'", conn, trans);<br />
417 }<br />
418 else { <br />
419 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);<br />
420 }<br />
421 } else {<br />
422 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);<br />
423 }
4. Configure my web.config in the same way as described in the author's original post...
5. Insert a record into my aspnet_profile database table with the same Application Name that I used in web.config and a "1" for my ApplicationId and NULL for PropertyValuesString
6. I am using the CreateUserWizard control customized to use Email as the UserName and take FirstName and LastName on registration. I set the "loginCreatedUser" property of the CreateUserWizard to "true" and handle the CreateUserWizard_CreatingUser event to copy the CreateUserWizard.UserName field into the CreateUserWizard.Email. I handle the CreateUserWizard_CreatedUser event to set Profile variables for the new user.
Hope this helps... There are a lot of Googleable guides to customizing the CreateUserWizard and setting Profile values, so I won't give my code there, just get 1-6 working and the examples using the default Microsoft providers will work the same. I think if you you follow these steps you will really find yourself in Hog Heaven as far as ASP.NET membership and profiles using MySQL are concerned.
modified on Monday, September 29, 2008 11:39 AM
|
|
|
|
|
yes its working.... thanks a lot
|
|
|
|
|
Here is the SQL code you need to run to make this work in MySQL 5. This also makes the UserID code an autoincrement key.
<br />
CREATE TABLE aspnet_profile (<br />
PKID varchar(36) collate latin1_general_ci NOT NULL default '',<br />
LastUpdatedDate datetime default NULL,<br />
PropertyNames text default NULL,<br />
PropertyValuesString text default NULL<br />
);<br />
<br />
<br />
CREATE TABLE aspnet_applications (<br />
ApplicationName text default NULL,<br />
ApplicationId int(11) default NULL,<br />
Description text default NULL,<br />
PropertyValuesString text default NULL,<br />
PRIMARY KEY (`ApplicationId`)<br />
);<br />
<br />
CREATE TABLE `users` (<br />
PKID varchar(36) NOT NULL default '',<br />
Username varchar(255) NOT NULL default '',<br />
ApplicationName varchar(100) NOT NULL default '' ,<br />
Email varchar(100) NOT NULL default '',<br />
`Comment` varchar(255) default NULL,<br />
`Password` varchar(128) NOT NULL default '',<br />
PasswordQuestion varchar(255) default NULL,<br />
PasswordAnswer varchar(255) default NULL,<br />
IsApproved tinyint(1) default NULL,<br />
LastActivityDate datetime default NULL,<br />
LastLoginDate datetime default NULL,<br />
LastPasswordChangedDate datetime default NULL,<br />
CreationDate datetime default NULL,<br />
IsOnLine tinyint(1) default NULL,<br />
IsLockedOut tinyint(1) default NULL,<br />
LastLockedOutDate datetime default NULL,<br />
FailedPasswordAttemptCount int(11) default NULL,<br />
FailedPasswordAttemptWindowStart datetime default NULL,<br />
FailedPasswordAnswerAttemptCount int(11) default NULL,<br />
FailedPasswordAnswerAttemptWindowStart datetime default NULL,<br />
ApplicationId bigint(20) default NULL,<br />
MobileAlias text NULL,<br />
IsAnonymous varchar(5) NULL default NULL,<br />
PRIMARY KEY (`PKID`)<br />
);<br />
modified on Friday, April 25, 2008 4:56 PM
|
|
|
|
|
Hi
I have created the tables as stated here.
But I still get a an 'Object not set to an instance of an object' error from this line 411
410 cmd = new MySqlCommand("SELECT PKID FROM aspnet_Profile WHERE PKID = '" + userId + "'", conn, trans);
411 object result = cmd.ExecuteScalar();
I have a good PKID value from the users table but the aspnet_profile table is empty so no records are returned from line 410.
I am attempting to create the profile when the user is initialy created.
Am I missing something here?
All the best
Hawkmoth
|
|
|
|
|
Ok think I got around it.
This is the original code in the MySQLProfileProvider.cs
410 cmd = new MySqlCommand("SELECT PKID FROM aspnet_Profile WHERE PKID = '" + userId + "'", conn, trans);
411 object result = cmd.ExecuteScalar();
412 string userid1 = result.ToString();
413 string userid2 = userId.ToString();
414 if (result != null && (userid1 == userid2)) {
415 cmd = new MySqlCommand("UPDATE aspnet_Profile SET PropertyNames ='" + names + "', PropertyValuesString ='" + values + "', LastUpdatedDate ='" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "' WHERE PKID ='" + userId + "'", conn, trans);
416 }
417 else {
418 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);
419 }
Line 412 fails cause result is null due to this being a new user with now profile yet.
userid1 is only used in line 414 as a check to make sure the profile matches the user.
So I moved it so the code now reads:-
410 cmd = new MySqlCommand("SELECT PKID FROM aspnet_Profile WHERE PKID = '" + userId + "'", conn, trans);
411 object result = cmd.ExecuteScalar();
412 if (result != null ) {
413 string userid1 = result.ToString();
414 string userid2 = userId.ToString();
415 if (userid1 == userid2){
416 cmd = new MySqlCommand("UPDATE aspnet_Profile SET PropertyNames ='" + names + "', PropertyValuesString ='" + values + "', LastUpdatedDate ='" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "' WHERE PKID ='" + userId + "'", conn, trans);
417 }
418 } else {
419 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);
420 }
All the best
Hawkmoth
modified on Thursday, August 7, 2008 11:04 AM
|
|
|
|
|
I noticed the same thing. In particular, changing the name in the aspnet_Profile table from UserId to PKID and changing the type of the same field from BIGINT to VARCHAR(36).
Also, I had to write code to insert an entry for the ApplicationName in the aspnet_Applications table to make sure it exists.
Finally I made the same changes as Hawkmoth with one exception:
410 cmd = new MySqlCommand("SELECT PKID FROM aspnet_Profile WHERE PKID = '" + userId + "'", conn, trans);
411 object result = cmd.ExecuteScalar();
412 if (result != null ) {
413 string userid1 = result.ToString();
414 string userid2 = userId.ToString();
415 if (userid1 == userid2){
416 cmd = new MySqlCommand("UPDATE aspnet_Profile SET PropertyNames ='" + names + "', PropertyValuesString ='" + values + "', LastUpdatedDate ='" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "' WHERE PKID ='" + userId + "'", conn, trans);
417 }
418 else {
419 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);
420 }
421 } else {
422 cmd = new MySqlCommand("INSERT INTO aspnet_Profile (PKID, PropertyNames, PropertyValuesString, LastUpdatedDate) VALUES ('" + userId + "','" + names + "','" + values + "','" + DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss") + "')", conn, trans);
423 }
The else clause at line 418 will make sure we don't fall though without initializing cmd at all.
|
|
|
|
|
First, we have to confige Web.config to accept anonymous user's operation
<^providers>
<^add name="MySqlProfileProvider"
type="Malachi.MySqlProviders.MySqlProfileProvider"
connectionStringName="ReportConnectionString2"
applicationName="Pro_report"/>
<^/providers>
<^properties>
<^add name="lastName" type="string" allowAnonymous="true" />
<^add name="firstName" type="string" allowAnonymous="true" />
<^/properties>
</profile>
<^anonymousIdentification
enabled="true"
cookieName=".ASPXANONYMOUS"
cookieTimeout="43200"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All"
cookieless="UseCookies"/>
Secondly, on line 388, string username = (string)sc["UserName"];
I actually get a value which equal to PKID's value when I create a user as anonymous user!!!!!
It will cause line 407 return a null value and fail to add a new profile record.
cmd = new MySqlCommand("SELECT PKID FROM Users WHERE UserName = '" + username + "'", conn, trans);
So, we have to let a visitor create a user and auto login first and then add profile records.
Thirdly, In "Get Profiles" Methods,the query command try to search the field "IsAnonymous" which is not exist in users table
line 690,700,710,721 string sqlQuery = "SELECT u.UserName, u.IsAnonymous,....
-- modified at 0:09 Monday 7th May, 2007
|
|
|
|
|
If you look at the table setup from the original member and role provider article there is a "IsAnonymous" field.
I am posting an updated zip file with all three source files. The Role,Membership, and profile source can be download from this article.
|
|
|
|
|
when I go to execute the command to create tables:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''aspnet_applications' (
'ApplicationName' text,
'ApplicationId' int(11) NO' at line 1
thanks!!!
"A terra é redonda mais nela cabem varias bestas quadradas"
|
|
|
|
|
|
I couldn't find the source too?
Nobody can provide a new reference to the source?
Thanks a lot.;)
|
|
|
|
|
Ditto, 404 File not found.
|
|
|
|
|
It's this one: http://www.codeproject.com/aspnet/MySQLMembershipProvider.asp
|
|
|
|
|
its all right in the schema and on the tables, but i'm getting this error, the membership and role provider is working good, but the provider have a lot of null reference.
|
|
|
|
|
Hi,
I have seen some strange behaviour with this, I'm not sure if it's by design or not, but let me explain.
I have a very basic page (just for testing this) that has one label. The Code-behind has the following code in the Page_Load function:
Label1.Text = Profile.FirstName;
Ok, that's fine, it calls GetPropertyValues as it should, but for some reason after it's done that, it calls SetPropertyValues as well - have you noticed it doing this? Do you know if it's supposed to do this? I would have thought that if you are simply reading a value then it would only need to call GetPropertyValues.
Thanks
Andy
|
|
|
|
|
I noticed that when I ported this from the Microsoft Access version. I don't know why that is in there. At the time I just wanted to get this to work with MySQL and the membership provider. I didn't really take time to optimize the code. I will take a look at it when I get a chance.
|
|
|
|
|
Has anybody got this working who is using Web Application Projects?
Ben.
|
|
|
|
|