|
<< Click to Display Table of Contents >> Usando mySQL |
![]() ![]()
|
Para usar o Profiles com mySQL é necessário ativar a configuração para que ela crie e grave os profiles no mySQL. Eu consegui fazer isso, mas apenas modificando o Machine.config. Talvez não seja fácil fazer isso num servidor da Web. Teria que testar antes de projetar todo o sistema.
Pense bem na possibilidade de usar variáveis de sessão ao invés de Profile, até porque profile é permanente (fica no banco).
Machine.config
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="MySQLProfileProvider" autogenerateschema="true" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" applicationName="/" />
</providers>
</profile>
Default.aspx
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
Profile.Nome = TextBox1.Text;
Response.Redirect("Default2.aspx");
}
Default2.aspx
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Default2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Profile.Nome;
}
web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer" connectionString="server=localhost;User Id=root;Persist Security Info=True;database=teste;password=123456" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
<system.web>
<profile defaultProvider="MySQLProfileProvider">
<properties>
<add name="Nome"/>
</properties>
</profile>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
Base mySQL
Teoricamente isso será criado sozinho no momento da primeira executação
#
# Structure for the `aspnet_applications` table :
#
CREATE TABLE `aspnet_applications` (
`ApplicationName` text,
`ApplicationId` int(11) NOT NULL AUTO_INCREMENT,
`Description` text,
PRIMARY KEY (`ApplicationId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
#
# Structure for the `aspnet_profile` table :
#
CREATE TABLE `aspnet_profile` (
`UserId` bigint(20) DEFAULT NULL,
`PropertyNames` text,
`PropertyValuesString` text,
`LastUpdatedDate` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_applications` table :
#
CREATE TABLE `my_aspnet_applications` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(256) DEFAULT NULL,
`description` varchar(256) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_membership` table :
#
CREATE TABLE `my_aspnet_membership` (
`userId` int(11) NOT NULL DEFAULT '0',
`Email` varchar(128) DEFAULT NULL,
`Comment` varchar(255) DEFAULT NULL,
`Password` varchar(128) NOT NULL,
`PasswordKey` char(32) DEFAULT NULL,
`PasswordFormat` tinyint(4) DEFAULT NULL,
`PasswordQuestion` varchar(255) DEFAULT NULL,
`PasswordAnswer` varchar(255) DEFAULT NULL,
`IsApproved` tinyint(1) DEFAULT NULL,
`LastActivityDate` datetime DEFAULT NULL,
`LastLoginDate` datetime DEFAULT NULL,
`LastPasswordChangedDate` datetime DEFAULT NULL,
`CreationDate` datetime DEFAULT NULL,
`IsLockedOut` tinyint(1) DEFAULT NULL,
`LastLockedOutDate` datetime DEFAULT NULL,
`FailedPasswordAttemptCount` int(10) unsigned DEFAULT NULL,
`FailedPasswordAttemptWindowStart` datetime DEFAULT NULL,
`FailedPasswordAnswerAttemptCount` int(10) unsigned DEFAULT NULL,
`FailedPasswordAnswerAttemptWindowStart` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='2';
#
# Structure for the `my_aspnet_profiles` table :
#
CREATE TABLE `my_aspnet_profiles` (
`userId` int(11) NOT NULL,
`valueindex` longtext,
`stringdata` longtext,
`binarydata` longblob,
`lastUpdatedDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_roles` table :
#
CREATE TABLE `my_aspnet_roles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`applicationId` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
#
# Structure for the `my_aspnet_schemaversion` table :
#
CREATE TABLE `my_aspnet_schemaversion` (
`version` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_sessioncleanup` table :
#
CREATE TABLE `my_aspnet_sessioncleanup` (
`LastRun` datetime NOT NULL,
`IntervalMinutes` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_sessions` table :
#
CREATE TABLE `my_aspnet_sessions` (
`SessionId` varchar(255) NOT NULL,
`ApplicationId` int(11) NOT NULL,
`Created` datetime NOT NULL,
`Expires` datetime NOT NULL,
`LockDate` datetime NOT NULL,
`LockId` int(11) NOT NULL,
`Timeout` int(11) NOT NULL,
`Locked` tinyint(1) NOT NULL,
`SessionItems` longblob,
`Flags` int(11) NOT NULL,
PRIMARY KEY (`SessionId`,`ApplicationId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_users` table :
#
CREATE TABLE `my_aspnet_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`applicationId` int(11) NOT NULL,
`name` varchar(256) NOT NULL,
`isAnonymous` tinyint(1) NOT NULL DEFAULT '1',
`lastActivityDate` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
#
# Structure for the `my_aspnet_usersinroles` table :
#
CREATE TABLE `my_aspnet_usersinroles` (
`userId` int(11) NOT NULL DEFAULT '0',
`roleId` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`userId`,`roleId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
#
# Structure for the `tabela` table :
#
CREATE TABLE `tabela` (
`id` int(11) NOT NULL,
`nome` varchar(20) NOT NULL,
`data` date NOT NULL,
`status` char(1) NOT NULL,
`salario` decimal(11,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
# Data for the `my_aspnet_applications` table (LIMIT 0,500)
#
INSERT INTO `my_aspnet_applications` (`id`, `name`, `description`) VALUES
(1,'/','MySQL Profile provider');
COMMIT;
#
# Data for the `my_aspnet_profiles` table (LIMIT 0,500)
#
INSERT INTO `my_aspnet_profiles` (`userId`, `valueindex`, `stringdata`, `binarydata`, `lastUpdatedDate`) VALUES
(1,'Nome/0/0/3:','AAA','','2011-01-24 20:54:10');
COMMIT;
#
# Data for the `my_aspnet_schemaversion` table (LIMIT 0,500)
#
INSERT INTO `my_aspnet_schemaversion` (`version`) VALUES
(6);
COMMIT;
#
# Data for the `my_aspnet_sessioncleanup` table (LIMIT 0,500)
#
INSERT INTO `my_aspnet_sessioncleanup` (`LastRun`, `IntervalMinutes`) VALUES
('2011-01-24 20:52:30',10);
COMMIT;
#
# Data for the `my_aspnet_users` table (LIMIT 0,500)
#
INSERT INTO `my_aspnet_users` (`id`, `applicationId`, `name`, `isAnonymous`, `lastActivityDate`) VALUES
(1,1,'Casa-PC\\Junior',0,'2011-01-24 20:52:31');
COMMIT;