|
Just wanted to thank you for sharing this! It saved me *many* hours of work!
Thanks++
karl
|
|
|
|
|
I have my site in vb. Whats the chances of getting this written in vb? I'm rather new to all this and wonder if I can do the conversion myself. Any suggestion on this would be helpful. Also, I was wondering why you were using compound indexes? I tried to cut and paste the table creation commands into the mysql command window, but have to remove the single quotes to get it to take. Tables were created and they seem correct, however.
Thanks
|
|
|
|
|
I don't think that you have to convert this in VB. asp.net normally supports multiple languages in the same website (you might have to compile the code and put the dll in \bin).
The quotes depend on the mysql version you use. The work fine on mine.
I'm not sure what you call compound indexes (i am french) but if you are talking about the indexes with multiple columns in the article, yes, that is a mistake. It should be a PRIMARY KEY as it was in the first versions of the article (I guess I made a copy/paste from a wrong version).
--
http://katro.net
|
|
|
|
|
Ok, I tired to compile this into a dll and got the following errors:
c:\dump\MySQLMembershipProvider.cs(6,7): error CS0246: The type or namespace
name 'MySql' could not be found (are you missing a using directive or an
assembly reference?)
c:\dump\MySQLMembershipProvider.cs(921,50): error CS0246: The type or namespace
name 'MySqlDataReader' could not be found (are you missing a using
directive or an assembly reference?)
I was using the csc.exe found in the Framework 2.0 dir and copied the cs file to a upper level directory as seen in my command:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215>csc /target:library /out:C:\dump\M
ySQLMembershipProvider.dll C:\dump\MySQLMembershipProvider.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50215.44
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50215
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
Now what do I do?
|
|
|
|
|
I was able to compile the cs file into a dll. But, I'm having errors in the web.config file. a few of the errors are like Andri.web.MysqlRoleProvider isn't the right type and items like connectionStringName is not declaired. I copied the config file right off the page, so I don't know what I'm doing wrong. Are these errors due to something being wrong in the web.config file, or in the compiled dll. I named the dll MysqlMembershipProvider.dll, if that makes any difference.
Thanks
|
|
|
|
|
I just wanted to let you know that I got it to work. I re-compiled the cs files and I found out that the Visual Web Developer has a bug that hasn't yet been fixed when reporting errors in the web.config/<providers> sections. I hope to write a post explaining what I did for others. Thanks a lot for these mysql providers. I'm just starting in with asp.net and these provider files are a real job saver.
|
|
|
|
|
Greetings:
How did you get the code to compile? I keep getting the same issue you were describing when running CSC (Type or namespace name 'MySql' could not be found).
How did you get around this? Thanks.
|
|
|
|
|
Hi!
Thanks a lot for this perfect solution... you saved me a couple of hours work *smile*
THANK YOU!
Reto
|
|
|
|
|
I have created a website using your providers as described in the article. The only thing I changed is the type of ApplicationName in the UsersInRoles table, which I set to Varchar.
Then I started testing. I created some Users with the CreateUserWizard control and added two Roles (User and Admin).
Everything works fine since yet.
But then I put a login control on a page and logged in.
Nevertheless the Page.User.Identity.Name is empty and the Page.User.Identity.IsAuthenticated is always false!
As excpected the IsOnline Property is true for all logged in users in Membership.GetAllUsers().
Is it a Bug or am I doing something wrong?
|
|
|
|
|
I found the solution for my problem. The Windows authentication was set as authentication type by default. It must be 'From the internet'.
|
|
|
|
|
Firstly i'd like to say these classes are just what I needed
Secondly I have a problem with the Initialize method of the MySqlMembershipProvider; it doesn't fire and hence it doesn't set the connectionstring. I'm using the same web.config as in your article. The weird thing is that the Initialize method of the MySqlRoleProvider DOES fire.
I can't figure out why this is happening...
|
|
|
|
|
Did you ever figure this out, why Initialize wasn't being called for MySqlMembershipProvider? I am having the same problem.
thanks
Ralph
|
|
|
|
|
No, I have no idea why. It works fine on my server.
|
|
|
|
|
Any way you could email me a small sample with configured .config settings essuark@yahoo-com. This is really killing me. Also, when should the Initialize method get called from the framework? When the user clicks on the logon button or when the project starts (in debuging, it never hits my break point). One other question, I read you dont need to write any code so I am quessing the framework calls the ValidateUser method once the user clicks on the login button or must there be code to call it??
thanks
Ralph
|
|
|
|
|
I know what you did wrong 'cause I did it myself!
You need to use Membership as a static class. Don't use MySqlMembershipProvider directly from code.
Hope this helps.
|
|
|
|
|
Hi,
I am using visual studio 2008 with frame work 3.5. For me also Initilize method is not calling.Can u help me...?
|
|
|
|
|
Hi
It seems that you have to fire it yourself. This example is of a AddUserToRole function.
<br />
public void AddUserToRole(string user,string role)<br />
{<br />
MySqlRoleProvider roleProvider = new MySqlRoleProvider();<br />
NameValueCollection config = new NameValueCollection();<br />
config.Add("connectionStringName", "MySqlConnection");<br />
config.Add("applicationName", "/");<br />
roleProvider.Initialize(null, config);<br />
<br />
roleProvider.AddUsersToRoles(new string[] { user },new string[] { role });<br />
<br />
}<br />
|
|
|
|
|
Hi,
Which version of mysql connector will help for calling initilize method by its owm?
|
|
|
|
|
Thanks for this great work! One thing I noticed however, is that after a user logs in (call to ValidateUser(...) method), the GetNumberOfUsersOnline(...) method still returns 0. This is caused by the fact that the LastActivityDate field is not updated in the ValidateUser(...) method. The MSDN description for the MembershipUser.LastActivityDate Property states that "... The LastActivityDate for a user is updated to the current date and time by the CreateUser and ValidateUser methods...".
The UPDATE statement in the ValidateUser(...) method should therefore look something like this:
MySqlCommand updateCmd = new MySqlCommand("UPDATE `" + tableName + "` SET LastLoginDate = ?LastLoginDate, " +<br />
"LastActivityDate = ?LastActivityDate " +<br />
" WHERE Username = ?Username AND ApplicationName = ?ApplicationName", conn);<br />
<br />
updateCmd.Parameters.Add("?LastActivityDate", MySqlDbType.VarChar).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");<br />
updateCmd.Parameters.Add("?LastLoginDate", MySqlDbType.Datetime).Value = DateTime.Now;<br />
updateCmd.Parameters.Add("?Username", MySqlDbType.VarChar, 255).Value = username;<br />
updateCmd.Parameters.Add("?ApplicationName", MySqlDbType.VarChar, 255).Value = pApplicationName;<br />
<br />
updateCmd.ExecuteNonQuery();
Other than that, nice job!
Gr,
Martin
|
|
|
|
|
Thank you oppie.
I have sent the new files to codeproject.com with your fix along with fixes from P. Kellner too. We now have to wait until the article gets updated.
|
|
|
|
|
This is a great piece of code that does exactly what I was looking for.
|
|
|
|
|
I don't want to update the article but I copy paste here a email I sent to somedy who asked if I was working on a profile provider. You might find it interresting.
>>>
I am not working on a custom provider for now. Writing a profile provider is a more complex task. It has to be generic enough so that we could add any property to the profile (it could be anything: name, zipcode, country, photos and avatars, etc.).
A quick way to store any data in the mysql db is to store the whole profile data as HashTable and binary serialize it into a largeblob field and then deserialize it everytime asp.NET asks for each single profile property. But then, it could cause a performance problem if the profile data is quite large. I think that receiving large data back and forth from a remote db server is a very bad idea, especially when you send the same exact request each time a profile property is requested.
Another idea is to dynamically create create/alter a mysql table each time the application is started and if the profile properties have changed. And to dynamically create SQL queries. This way, We receive only the request profile data. I think this is a much better idea but it requires a *LOT* more coding.
<<<
|
|
|
|
|
Do we know how they do this with the MS SQL Server implementation?
Haven't looked at it but with SQL Profiler we could figure that out and build something similar maybe.
Otherwise, what about caching? Wouldn't that be a perfect situation for caching? Lot's of reads from the same object, little updates...and we do have good caching support in .NET.
Cool stuff by the way, we were thinking about switching to SQL server too, but will rethink that again.
Cheers
Remy
Remy Blaettler
Chief Technical Architect
Collaboral.com
|
|
|
|
|
I like the membership provider. Any update on a timeline for the profile provider?
thanks
|
|
|
|
|
if you get the error "Max key length is 500", reduce the size of the fields so that the sum is less than 500.
|
|
|
|