|
I try to do this:
DateTime dt = new DateTime(2001, 1, 1);
u.LastActivityDate = dt;
Membership.UpdateUser(u);
But apparently dt is formatted like 01-01-2001 00:00:00 where MySQL expects 2001-01-01 00:00:00
Any ideas?
|
|
|
|
|
Thanks for your question. I just realized that I didn't include everything in the SQL command.
"UPDATE `users` SET Email = ?, Comment = ?,IsApproved = ? WHERE Username = ? AND ApplicationName = ?"
That's the command that's executed on UpdateUser. I will get working on it right away.
Thanks again!
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
** Remember: An article is only as good as the votes it gets **
|
|
|
|
|
Hi again,
any new on the above? I tried downloading the sourcecode, but it still has
"UPDATE `" + tableName + "`" +
" SET Email = ?, Comment = ?," +
" IsApproved = ?" +
" WHERE Username = ? AND ApplicationName = ?"
I guess I could try and correct it myself, but do you have an updated sourcefile that you didn´t upload yet?
|
|
|
|
|
I've submitted an update for the change.
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
** Remember: An article is only as good as the votes it gets **
|
|
|
|
|
Hmmm.... where? When I download the sourcecode (top pf the page: "Download source - 182.1 KB" ), I still get this code (MysqlMembershipProvider.cs, line# 1199);
public override void UpdateUser(MembershipUser user)
{
OdbcConnection conn = new OdbcConnection(connectionString);
OdbcCommand cmd = new OdbcCommand("UPDATE `" + tableName + "`" +
" SET Email = ?, Comment = ?," +
" IsApproved = ?" +
" WHERE Username = ? AND ApplicationName = ?", conn);
cmd.Parameters.Add("@Email", OdbcType.VarChar, 128).Value = user.Email;
cmd.Parameters.Add("@Comment", OdbcType.VarChar, 255).Value = user.Comment;
cmd.Parameters.Add("@IsApproved", OdbcType.TinyInt).Value = user.IsApproved;
cmd.Parameters.Add("@Username", OdbcType.VarChar, 255).Value = user.UserName;
cmd.Parameters.Add("@ApplicationName", OdbcType.VarChar, 255).Value = pApplica
|
|
|
|
|
When i create a new user in simple code below :
Membership.CreateUser("test", "test");
Got the error :
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source Error:
Line 1068: finally<br />
Line 1069: {<br />
Line 1070: conn.Close();<br />
Line 1071: }<br />
Line 1072:
Source File: MysqlMembershipProvider.cs Line: 1070
Stack Trace:
[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]<br />
System.Data.Common.UnsafeNativeMethods.SQLFreeHandle(SQL_HANDLE HandleType, IntPtr StatementHandle) +0<br />
System.Data.Odbc.OdbcHandle.ReleaseHandle() +71<br />
System.Runtime.InteropServices.SafeHandle.InternalDispose() +0<br />
System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing) +11<br />
System.Runtime.InteropServices.SafeHandle.Dispose() +9<br />
System.Data.Odbc.CMDWrapper.DisposeStatementHandle() +59<br />
System.Data.Odbc.CMDWrapper.Dispose() +30<br />
System.Data.Odbc.OdbcCommand.CloseCommandWrapper() +33<br />
System.Data.Odbc.OdbcCommand.CloseFromConnection() +37<br />
System.Data.Odbc.OdbcReferenceCollection.NotifyItem(Int32 message, Int32 tag, Object value) +73<br />
System.Data.ProviderBase.DbReferenceCollection.Notify(Int32 message) +91<br />
System.Data.Odbc.OdbcConnectionOpen.Deactivate() +18<br />
System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory) +106<br />
System.Data.Odbc.OdbcConnection.Close() +38<br />
Simple.Providers.MySQL.MysqlMembershipProvider.GetUserNameByEmail(String email) in MysqlMembershipProvider.cs:1070<br />
Simple.Providers.MySQL.MysqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) in Simple.Provider\MysqlMembershipProvider.cs:426<br />
System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +224<br />
System.Web.Security.Membership.CreateUser(String username, String password, String email) +30<br />
System.Web.Security.Membership.CreateUser(String username, String password) +6<br />
TestUser.btCreateUser_Click(Object sender, EventArgs e) +16<br />
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105<br />
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107<br />
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7<br />
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11<br />
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33<br />
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
What do you think?
|
|
|
|
|
I have got the answer. It's a bug. I will post my edited code soon.
|
|
|
|
|
Hi Jacques,
I don't know if it is beyond the scope of this article but perhaps you can share your thoughts about the following..
MySql is often used by shared hosting providers as a cheap alternative to SQLServer and by users considered as fast enough to start building a website. Often you see it combined with the support of ODBC. Most hosting providers work with medium trust and the first things they allow to use is ODBC. So that's why your article will be very welcome to most readers.
But there seems to be a problem in the initialize method of the MySqlMemberShipProvider class. After closer inspection I found the WebConfigurationManager.OpenWebConfiguration method to be the trouble maker. When googling you will find that this method tries to open the web.config for read and write. Now that shouldn't be a problem but it also wants to inherit all settings from config files that are 'above it' like machine.config etc. and that is not allowed in medium trust.
You can see how this (not) works when you add the line:
<trust level="Medium" /> in your \system.web part of your web.config.
Read some more on it in: http://msdn2.microsoft.com/en-us/library/ms998341.aspx#paght000020_mediumtrustsummary
For now I solved it by just making my own machineKey (not getting it out of the web.config file) but I like to hear how other people solved it..
|
|
|
|
|
I would have never picked that up, as I'm running my sites from virtual hosts.
I personally think it's very important to resolve this issue in a new release and will research it and update the article as soon as possible.
Any comments and/or suggestions are always welcome.
Thanks again!
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
** Remember: An article is only as good as the votes it gets **
|
|
|
|
|
Hi,
it works very good. I found (and solve) only two little problems:
1. my ISP uses old MySQL version and table names are case sensitive
2. if you don't need hashed password, you can change the code to:
if (PasswordFormat == MembershipPasswordFormat.Hashed)
{
// Get encryption and decryption key information from the configuration.
Configuration cfg =
WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
machineKey = (MachineKeySection)cfg.GetSection("system.web/machineKey");
if (machineKey.ValidationKey.Contains("AutoGenerate"))
throw new ProviderException("Hashed or Encrypted passwords " +
"are not supported with auto-generated keys.");
}
This little change works for me good in medium trust level - I have tried to use Clear and Encrypted passwords (encrypted passwords with machineKey set in web.config file).
|
|
|
|
|
Thanks for the pointers. Will keep it in mind for the next release!
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
** Remember: An article is only as good as the votes it gets **
|
|
|
|
|
Hmm. I think that you could use the machineKey only for encryption and not with the hash. You can hash without machinekeys (am I right?) and also add a field passwordSalt to the users table for better security.
Great work anyway!!!
|
|
|
|
|
Thanks!
I think you are right and the passwordSalt field is a great idea if you are concerned about security.
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
** Remember: An article is only as good as the votes it gets **
|
|
|
|
|
OpenWebConfiguration method is working with full trust level only. It cannot work in medium trust level.
|
|
|
|
|
Hi, I'm a heavy MySQL user for all my windows and web applications. I have already create one for most common function such as retrive data reader from a SQL statement, get count and etc.
Infact I'm thinking of creating one provider which will use the ASP controls with MySQL database. I haven't tested your code but I'm sure will update you in case I have some suggestion or issues to be shared with. Meanwhile, you may share some issue and information with me. My email address is irwanhassan@hotmail.com.
|
|
|
|
|
Hi Irwan,
Thank you for your comment. Most of the issues has been discussed in the comments on this article. If you come accross any more issues, don't hesitate to contact me.
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
* Remember: An article is only as good as it's votes!
|
|
|
|
|
If you open the web site admin tool, it only shows that a timeout occurs. Otherwise, the suite seems to work perfectly. Any ideas how to make this work
?
thanks,
Dan
|
|
|
|
|
I don't really use the website administration tool. The tool might be calling some method that doesn't function as expected (eg. returns null instead of some data).
I'll have a look at this as soon as possible and get back to you. Thanks for your comment.
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
An article is only as good as the votes it gets.
|
|
|
|
|
I could use the Role and Membership stuffs with MySQL finally.. Thanks so much!
|
|
|
|
|
Thanks! Now I've got I nice glow around me
Tell your friends, and remember... An article is only as good as it's votes!
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
|
|
|
|
|
Your article came just at the right time. Working like a charm! Some minor comments..
In the personalizationProvider description your missing a double quote. I had some problems with the Table Names.. perhaps its a setting in my MySQL DB 'cause the table names had to be proper case so 'Users' instead of 'users' and UsersInRoles etc. Other than that it seems to work.. Thanx!
|
|
|
|
|
Thank you very much. I know that MySQL has a setting somewhere to enable case sensitivity. The DB I was developing was case insensitive so that's probably why I didn't pick it up. When you say
jvkaam wrote: In the personalizationProvider description your missing a double quote
Where exactly is it? I don't have the same problem?
Thanks again for the comments.
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
|
|
|
|
|
In the description it says:
description="MySQL Personalization Provider/>
and should be
description="MySQL Personalization Provider"/>
It's hardly worth talking about.
Anyway keep up the good work.
|
|
|
|
|
Hi boet!
Yip. Well done on this one!
|
|
|
|
|
Thanks boet!
"I'm about as expert as a palsy victim performing brain surgery with a pipe wrench."
Check out my site at JacquesSnyman.co.za
|
|
|
|