|
Can you tell me how to make the code using ODBC instead of MySQL Connector? Share me please
|
|
|
|
|
For some reson i get an error when i try to use the sql you have writen, the only part of it i can execute in any way is the creation of the Role table. the rest is buggy, ie. the Text in the creation of the userinroles, make an error, as far as I remember it's cause you can't make a limiter on such a fiel, I tryed to change it to a Varchar and that worked, but the rest i can't fix, neither the Alter's nor the user table
Hope someone is able to help me out on this.
|
|
|
|
|
sql language in mysql changes from one version to another. Just create the tables and the primary keys with whatever tools you have.
--
http://katro.net
|
|
|
|
|
To make these providers work on a VB website, you will need to compile them with csc.exe and reference the mysql driver that you are using. To do so:
1. Place the MySqlMembershipProvider.cs and the MySqlRoleProvider in the App_Code dir on the machine that your website will run on.
2. Do a search on your pc for csc.exe. You will probably have a few of these in different directories. Use the one in your WINDOWS\Microsoft.NET\Framework\v2.0.xxxxx directory. Open a command prompt window and cd to this directory (cd \WINDOWS, then cd Microsoft.NET and so on). Once in this directory, you will need to type in the command to compile each .cs file. Depending on which MySql Driver you are using, you will need to add a reference to it in the compile command with the /r switch.
The command I used looked like:
csc /r :\Inetpub\wwwroot\bin\MySql.Data.dll /target:library /out :\Inetpub\wwwroot\bin\MySqlMembershipProvider.dll D:\Inetpub\wwwroot\App_Code\MySqlMembershipProvider.cs
You won't put any line breaks in. This is all one line. Do he same for the role provider. Also, don't compile these on one machine and expect them to work on another.
Once it has compiled, you should be able to start the website Administration page, select 'Security' and you should be able to add users and what not.
The only thing you can't do, or will fail if you try, is to test the providers. Otherwise, it works. You might read the rest of the comments for info on setting up the tables.
Happy Motoring!
|
|
|
|
|
Hi Nakins,
Need your assistance to check on the compile command stated above. I had downloaded the MySQL ODBC/Connector driver 3.51 but was unable to find MySql.Data.dll inside my laptop.
I am currently trying to develop a .NET application that inerfaces with MySQL as a backend db.I had tried to compile MySqlMembershipProvider.cs with the command you had stated above. However, I was unsuccessful in doing so as there are errors from the command. They are copied as follows below.
Just another question, do I have to move all of my development files into the ~\Inetpub\wwwroot\ folder?
Thanks in advance for your help!
Errors messages:-
error CS2001: Source file 'Project\EAMS' could not be found
error CS2001: Source file 'Program\EAMS\App_Data\MySqlMembershipProvider.dll'
could not be found
error CS2001: Source file 'D:\Academic\Wales' could not be found
error CS2001: Source file 'Project\EAMS' could not be found
error CS2001: Source file 'Program\EAMS\App_Data\MySqlMembershipProvider.cs'
could not be found
fatal error CS2008: No inputs specified
Cheers,
Jazzyjas78
|
|
|
|
|
Well, first of all, there are two mysql drivers. there is the MyODBC driver you have, and there is the Connector.NET driver. I use both. You need to download the Connector.NET driver (from MySql) and place it in your bin folder that is located in your Inetpub/wwwroot for your project directory. I can't remember if there was any speical instructions needed for this, so, you might look around to find instruction on how to install theConnector.net driver.
Use the Inetpub/wwwroot directory structure to develop and to run live. So, yes, you need to move your files to that directory.
Once you get these things done, try compling again like I stated.
|
|
|
|
|
Hi Nakins,
Thanks for your advice! I had managed to compile the two .dll files successfully. However, when I went into ASP.NET Web Site Admin Tool, I received the same error you had encountered earlier regarding errors in the web.config file.
Error message is like this; "The following message may help in diagnosing the problem: Could not load type 'Andri.Web.MySqlMembershipProvider'. (D:\Academic\Wales Project\EAMS Program\EAMS\web.config line 35)"
Thanks for your help so far and sorry for bothering you repeatedly today!
Cheers,
jazzyjas78
|
|
|
|
|
You won't be able to select the role provider in the admin tool. Why? I don't know. But you should be able to go to security or the users section, whatever it is, and be able to add users and roles and such.
Here is what my config file looks like. Your will be different in the connection strings and the application name. Hope this helps. I'll be gone the rest off the day.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="mydbConnectionString" connectionString="DATABASE=db;DSN=myodbc;OPTION=0;PORT=0;UID=me"
providerName="System.Data.Odbc" />
<add name="connectionString" connectionString="Database=db;Data Source=localhost;User Id=admin;Password=admin" />
<add name="HomeConnectionString" connectionString="Dsn=myodbc2;uid=me;pwd=me"
providerName="System.Data.Odbc" />
</connectionStrings>
<system.web>
<authentication mode="Forms" />
<authorization>
</authorization>
<compilation debug="true"/>
<membership defaultProvider="MySqlMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="MySqlMembershipProvider" type="Andri.Web.MySqlMembershipProvider" connectionStringName="connectionString" applicationName="myWebSite" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" writeExceptionsToEventLog="true"/>
</providers>
</membership>
<roleManager defaultProvider="MySqlRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<clear/>
<add name="MySqlRoleProvider" type="Andri.Web.MySqlRoleProvider" connectionStringName="connectionString" applicationName="myWebSite" writeExceptionsToEventLog="true"/>
</providers>
</roleManager>
</system.web>
</configuration>
-- modified at 13:54 Sunday 26th February, 2006
|
|
|
|
|
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 />
|
|
|
|