i am using asp.net mvc2 with mysql db. i add mysql membership provider,profileprovider,role provider for mysql.the i use asp.netconfiguration tool to create roles.it works and create roles.then i try to login at that time it shows The user name or password provided is incorrect.when i create role defaul mysql membership,role tables are created in the database.
my wb config provider initialization part is as follows.
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<clear />
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" applicationName="MYAPP" writeExceptionsToEventLog="False" autogenerateschema="True" enablePasswordRetrieval="False" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
<profile defaultProvider="MySQLProfileProvider">
<providers>
<clear />
<add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" autogenerateschema="true" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySQLRoleProvider">
<providers>
<clear />
<add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.3.5, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="ApplicationServices" autogenerateschema="true"/>
</providers>
</roleManager>
any one know why it doent allow to login.
I know its the obvious - but have you gone into the new db and ensured the login information and password are indeed correct?
You mentioned you created the roles - but no mention of creating the users, which you would need to do in the aspnet tool as well.
Related
I am using Visual Studio 2013 to develop a web forms application. I selected Authentication: Individual user accounts. I want the application including ASP Identity to use MySQL.
I added references to MySql.Data, MySql.Data.Entity.EF6, MySql.Web and have made the following changes to Web.config:
<connectionStrings>
<add name="EkoPayMaster.Properties.Settings.EkoPayMasterConnectionString" connectionString="server=localhost;user id=root;persistsecurityinfo=True;database=paymaster" />
</connectionStrings>
<membership defaultProvider="MySqlMembershipProvider">
<providers>
<clear />
<add name="MySqlMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web" connectionStringName="EkoPayMasterConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" autogenerateschema="true" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add type="MySql.Web.Security.MySqlProfileProvider, MySql.Web" name="MySqlProfileProvider" applicationName="/" connectionStringName="EkoPayMasterConnectionString" autogenerateschema="true" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="MySqlRoleProvider">
<providers>
<clear />
<add connectionStringName="EkoPayMasterConnectionString" applicationName="/" name="MySqlRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web" autogenerateschema="true" />
</providers>
</roleManager>
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"></remove>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0" />
</DbProviderFactories>
</system.data>
When I run the application, I am able to register a user and log in. However, ASP Identity does not create the necessary user tables is the MySql database.
What do I need to do to have the application add the tables/user information into MySql?
First of all, as I know, you must use exactly the same connection string name you gave in connectionStrings/add name in all your providers' connectionStringName attributes.
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Is the above relevant? I just have it in there in order not to screw things further.
But below is what I'm interested in, it is a connection string of my local sql server
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=TestDB;User ID=lews;Password='therin'" providerName="System.Data.SqlClient" />
"When you create a database on Sequelizer you can specify a connection string alias. This is done on the Sequelizer add-on page (follow the "Go to ..." link on the application overview). If you set this name as the name of your connection string in your configuration file, we'll automatically replace it with your Sequelizer connection string when your code is deployed."
That's a snippet from Appharbor's documentation. So I assume that Data Source, Initial Catalog, User ID and password is automatically replaced with the correct values by AppHarbor. But it can't connect for some reason.
Below is another string I am using with MySQL this time, again I assume that AppHarbor should automagically inject the right values, but the error it gives is:
"PeopleEntities cannot be found in the application configuration file"
What is going on?
<add name="PeopleEntities" connectionString="metadata=res://*/Context.People.csdl|res://*/Context.People.ssdl|res://*/Context.People.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;database=people"" providerName="System.Data.EntityClient" />
</connectionStrings>
Btw, the names "PeopleEntities" and "ApplicationServices" are used as aliases on AppHarbor.
And I have no idea how to use the code given in the documentation, databases is just not my thing.. how do I use both local and remote conn strings? Where in the code do I build the string and inject it? Do I have to do it whenever I create a DBContext instance? Etc..
Any ideas will be great, thanks!
EDIT:
Btw, if I hard code the connection strings, in the app.config and use a wcftestclient, it works, it queries the database.. but this isn't a good idea, apparently the connection strings can change without warning.
Anyway if I deploy it with the strings hardcoded and connect to the database with my site.. it doesn't query the SQL server.. really confused :(
http://support.appharbor.com/discussions/problems/2687-solved-mysql-provider-with-entity-framework-problem
For Entity Framework:
This piece of markup is unbelievable important:
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Oh make sure the MySQL connector assemblies are local. And it should be in your web.config file as well, to be extra sure place it in your WCF's App.config. Use the same addon alias in your connection string.
For SQL Server addon:
You need this markup in the web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
</system.web>
And you should be good to go..
I am a newbie in ASP.net and just following Tutorials. This Particular Problem has been Giving me a Real Headache, I have developed a website in VS 2010 , used the ASPNETDB SQL server database provided by Asp.Net Login Controls for creating users and roles. Also added Some tables, After i Was Done Used the " publish to Provider " feature to generate the Script (ASPNETDB.MDF.sql) . I Used this Script to Generate the Database and Tables -Sql Server 2008 R2 management Studio, and Modified the web.config Like This-
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Server=AkumJamir-PC\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<roleManager enabled="true">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add connectionStringName="ConnectionString" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider,System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove name="AspNetWindowsTokenProvider"/>
</providers>
</roleManager>
<membership>
<providers>
<remove name="AspNetMembershipProvider"/>
<add connectionStringName="ConnectionString" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphaNumericCharacters="1" passwordAttemptWindow="5" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider,System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
<webParts>
<personalization defaultProvider="AspNetSqlPersonalizationProvider">
<providers>
<remove name="AspNetSqlPersonalizationProvider"/>
<add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.Webparts.SqlPersonalizationProvider"
connectionStringname="ConnectionString" applicationName="/"/>
</providers>
</personalization>
</webParts>
Now The Problem is That Works On my Development Machine But on our Staging Server, It Doesnt connect to the Database whenever i try browse to Some Pages where i have some data to be displayed from the Database Neither Does the Login Page Work.The connectionString Looks Like This in the Server:
<!--Connection String-->
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Driver={SQL Native Client};Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="con" connectionString="Server=WIN-K16NMM4128C;Initial Catalog=ASPNETDB;Integrated Security=True"/>
<add name="ConnectionString" connectionString="Data Source=WIN-K16NMM4128C\SqlServer2008;Initial Catalog=ASPNETDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
I Am Eating My braings Away, I've Gone through the Topics Covered Already,,,, Thanks For any Advise...
I was facing the same issue. I've just enabled ASP/Authentication in IIS manager and I've set Basic Authentication=true. It is working now.
You are using integrated security in your connection strings. Configure it to use sql authentication. Something like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
First, my development environment: Win7 laptop with Visual Studio Professional 2010. IIS is NOT installed.
I'm trying to turn on and set up some roles for user management via the ASP.NET Configuration Tool, as demonstrated in the MVCMusicStore tutorial. When I click on the 'Security' tab, I get the following error:
"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Could not load type 'HandiGamer.MvcApplication'."
When I click on the 'button below', it tells me I'm using AspNetSqlProvider as my provider. When I try to test it, it tells me:
"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."
Here's the thing:
The MVCMusicStore demo's role/user management works when I run it through the debugger. I can add myself as a customer, and add/remove items from my cart. Despite this, when I attempt to use the Configuration Tool with it, I get the same errors.
I actually have run aspnet_regsql on my copy of SQL Server 2008 Express. It created the necessary tables for user management. Still didn't fix my problem.
I'm just wondering if I'm missing something obvious, as the tutorial essentially said "Click two buttons and you're all set." It literally said nothing about setting up the db for this.
I'm just stumped at this point. Role/user management works (the MVCMusicStore proves that it does), but the configuration tool won't let me turn it on, set it up, or otherwise edit how it works. It's becoming very frustrating. Any help would be greatly appreciated.
EDIT: My web.config is as follows-
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="HandiGamer" connectionString="data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|handigamer.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="HandiGamer" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="HandiGamer" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Found the solution. Had to compile/build my solution before the config tool would 'see' the db security stuff.
I am trying to use the ASP.NET forms authentication service with the MySQL connector version 6.3.2. I was able to get it working using cleartext passwords but unable to get hashed passwords working. Here is a snippet from my machine.config file
<system.web>
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<add name="MySQLMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
autogenerateschema="true"
connectionStringName="LocalMySqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression="" />
</providers>
</membership>
</system.web>
I am using the ValidateUser method of the MembershipProvider class to perform authentication. If the line passwordFormat="Hashed" is changed to passwordFormat="Clear" users will authenticate. After changing settings in the machine.config file I remove all users and recreate the accounts. I inspected the contents of the aspnet tables and the passwords are being stored properly as hashes - just failing to verify.
Looks like I'm not the only one who has noticed this bug: http://forums.mysql.com/read.php?38,368612,372250. Easily fixed by adding the following to the web.config:
<system.web>
<machineKey validationKey="AutoGenerate" validation="SHA1" />
</system.web>