D01 Using MySql as a Storage for IIS (Wpf, Xamarin) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
Please read the following article: https://docs.microsoft.com/en-us/aspnet/identity/overview/extensibility/implementing-a-custom-mysql-aspnet-identity-storage-provider
Download and install Mysql in your local or virtual environment
- goto https://dev.mysql.com/downloads/
- download and run Installer
- make sure to install "MySQL Workbench"
Create new user with "root"-privilege
- run "MySQL Workbench"
- login as root
- execute the following script
CREATE USER 'rt'@'%' IDENTIFIED BY '*********';
GRANT ALL PRIVILEGES ON *.* TO 'rt'@'%' WITH GRANT OPTION;
- where
- "rt" is a name (you can use any name you like)
- "*********" - is a password (type the passwrd you like)
- "%" - tells mysql that you can login not only from "localhost"-machine!!!!!
install Connector/NET on the developer machine (or on a machine where IIS is installed)
- goto https://dev.mysql.com/downloads/
- download and run Connector/NET
- choose the correct version (each version of MySql has its own "Connector/NET")
- download and run Connector/NET
install MySql.Data.EntityFramework
- with VS2019 open Dm04WebApp and install MySql.Data.EntityFramework nuGet-package
- choose the correct version with "Connector/NET"
Modify Web.config (and App.config)
-
read an article https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
-
Web.config:
- App.config (We used small console app. So here is config file for it)
Create AspNet Identity tables on the MySql server
- run "MySQL Workbench"
- login as root
- execute the following script
USE AspNetDbWebApplicationMobileSecurity;
CREATE TABLE `aspnetroles` (
`Id` varchar(128) NOT NULL,
`Name` varchar(256) NOT NULL,
PRIMARY KEY (`Id`)
);
CREATE TABLE `aspnetusers` (
`Id` varchar(128) NOT NULL,
`Email` varchar(256) DEFAULT NULL,
`EmailConfirmed` tinyint(1) NOT NULL,
`PasswordHash` longtext,
`SecurityStamp` longtext,
`PhoneNumber` longtext,
`PhoneNumberConfirmed` tinyint(1) NOT NULL,
`TwoFactorEnabled` tinyint(1) NOT NULL,
`LockoutEndDateUtc` datetime DEFAULT NULL,
`LockoutEnabled` tinyint(1) NOT NULL,
`AccessFailedCount` int(11) NOT NULL,
`UserName` varchar(256) NOT NULL,
PRIMARY KEY (`Id`)
UNIQUE KEY `UNIQ_AspNetUsersUserName` (`UserName`)
);
CREATE TABLE `aspnetuserclaims` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`UserId` varchar(128) NOT NULL,
`ClaimType` longtext,
`ClaimValue` longtext,
PRIMARY KEY (`Id`),
UNIQUE KEY `Id` (`Id`),
KEY `UserId` (`UserId`),
CONSTRAINT `ApplicationUser_Claims` FOREIGN KEY (`UserId`) REFERENCES `aspnetusers` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
);
CREATE TABLE `aspnetuserlogins` (
`LoginProvider` varchar(128) NOT NULL,
`ProviderKey` varchar(128) NOT NULL,
`UserId` varchar(128) NOT NULL,
PRIMARY KEY (`LoginProvider`,`ProviderKey`,`UserId`),
KEY `ApplicationUser_Logins` (`UserId`),
CONSTRAINT `ApplicationUser_Logins` FOREIGN KEY (`UserId`) REFERENCES `aspnetusers` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
);
CREATE TABLE `aspnetuserroles` (
`UserId` varchar(128) NOT NULL,
`RoleId` varchar(128) NOT NULL,
PRIMARY KEY (`UserId`,`RoleId`),
KEY `IdentityRole_Users` (`RoleId`),
CONSTRAINT `ApplicationUser_Roles` FOREIGN KEY (`UserId`) REFERENCES `aspnetusers` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT `IdentityRole_Users` FOREIGN KEY (`RoleId`) REFERENCES `aspnetroles` (`Id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ;
With console app create Databases and populate tables with data
- we do not need to change the code!!!
- just run our console app and create databases
- just run our console app and populate tables with data
Start Dm04WebApp, run Uwp-app(or Android app) and register some user
- Register new user
- here is a result:
- getting data: