|
I chose your code for a project, where the Profile is important. But Profile function always give an exception.
1. I use a CreateUserWizard which has a step ask for user's profile, in the CreatedUser function, set this profile.
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Profile.NickName = txtNickName.Text;
}
But it give an exception: Provider Exception! Cannot set it for an annonymous.
2. When I logined in, I set the Profile like this:
protected void btnSaveProfile_Click(object sender, EventArgs e)
{
Profile.NickName = txtNickName.Text;
Profile.Sex = RdSex.Text;
Profile.UserCompany = txtCompany.Text;
}
But an Exception ocurred: Unsupported property.
I use MySQL 5.0.
Can you help me.
I'm a chinese with poor english.
|
|
|
|
|
Hi...
You need to make changes to the code, database and web.config if you need custom properties for a profile. The "Unsupported property" exception you're getting is probably because of this.
The "Cannot set for anonymous" exception is because of the fact that you cannot set a profile property unless the user is logged in.
I'm working on making the profile properties dynamic so that the code and database can handle it.
Thanks
Jacques
"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 **
|
|
|
|
|
First, Thanks for your replay!
ERROR Comes from a file autogenerated in APP_CODE folder, The first Error reported "Unsupported property." in the NickName's this.SetPropertyValue function.
*****************************************************************
public class ProfileCommon : System.Web.Profile.ProfileBase {
public virtual string NickName {
get {
return ((string)(this.GetPropertyValue("NickName")));
}
set {
this.SetPropertyValue("NickName", value);
}
}
*******************************************************************
This is my profile:
*******************************************************************
<profile defaultProvider="profileProvider" automaticSaveEnabled="true">
<providers>
<clear/>
<add
name="profileProvider"
type="Simple.Providers.MySQL.MysqlProfileProvider"
connectionStringName="SimpleProviderConnectionString"
applicationName="CFH"
description="MySQL Profile Provider"/>
</providers>
<properties>
<clear/>
<add name="NickName" />
<add name="Sex" />
<add name="UserCompany" />
</properties>
</profile>
***************************************************************
And the database was created by sql file in your codes.
So, What should I do? Help me!
-- modified at 22:05 Monday 9th July, 2007
|
|
|
|
|
You should add the following line to the profiles create table sql script:
`NickName` varchar(255) NOT NULL default '',
Hope this helps!
"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 **
|
|
|
|
|
I don't know how Profiles works, but in your code, It seems difficulty. I must add a new column in the the table, then I must add corresponding code in the MysqlProfileProvider.cs file.
But the guide book of ASP.NET says, you can add any Profile Items anytime, just like Seesions does.
So why don't you save all the Profiles items in same table structure?
MySQL Provider suit is very important to devlopers who use ASP.NET 2.0 + MySQL Suit, it's the first thing! But I can't find a very good solution content myself.
Would you like change your code or find out a solution to us?
|
|
|
|
|
I already have this in mind and the solution should be quite easy, but I just don't get time to do dev work. Maybe someone can make the change and send me the changed code.
I will try and get to this asap if I don't get any change suggestions, so please, just hang in there.
"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 **
|
|
|
|
|
Hey
Do you have a solution in the near future? Because I'm in the need for the custom attributes, and would like to know, if I can wait for you to do the job...
If not, it could be nice to hear your ideas for an implemention
regars...
|
|
|
|
|
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.
|
|
|
|