Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 7th, 2006, 11:22 AM
Registered User
 
Join Date: Aug 2006
Location: Seattle, WA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Edit User Profile - email

I want to be able to change an email address after a user has been created. Is there a security reason a user cannot change his email address when editing his profile? I tried to add this feature but I get an error message 'There is no definition for 'Email' in ProfileGroup... or ProfileCommon...' Not sure where exactly Marco defined the attributes, but when I click on Definition a file is 'Auto-generated' that appears to have all the class definitions - C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\tbh_web\21e78ee0\8caff75f\Sources_App_Code\p rofile.cdcab7d2.cs

Problem is I can't find this file in the solution.

Can anyone help me with this ridiculously simple task?

Thanks,
Gary
  #2 (permalink)  
Old August 7th, 2006, 01:41 PM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 99
Thanks: 0
Thanked 1 Time in 1 Post
Default

Email addresses are stored in the table aspnet_Membership. It doesn't require a profile entry as the functionality is provided free. Nobody needs to write code for it to work, hence your discovery of the 'Auto-generated' class definitions.

I'm going to guess that to provide your functionality isn't a ridiculously simple task.

  #3 (permalink)  
Old August 7th, 2006, 06:34 PM
Registered User
 
Join Date: Aug 2006
Location: Seattle, WA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks MM; maybe you can help me understand where the Profile functionality starts, and how I can define 'Email' inside of it..

Here is an excerpt from the end of the Controls/UserProfile.ascx.cs file:

      
Code:
ddlOccupations.SelectedValue = profile.Occupation;
Code:
            txtWebsite.Text = profile.Website;
            txtStreet.Text = profile.Address.Street;
            txtCity.Text = profile.Address.City;
            txtPostalCode.Text = profile.Address.PostalCode;
            txtState.Text = profile.Address.State;
            ddlCountries.SelectedValue = profile.Address.Country;
            txtPhone.Text = profile.Contacts.Phone;
            txtFax.Text = profile.Contacts.Fax;
            txtAvatarUrl.Text = profile.Forum.AvatarUrl;
            txtSignature.Text = profile.Forum.Signature;
         }
      }

What I tried to do was duplicate the code in red, changing the Fax value to Email. In the .ascx file I created the appropriate text box; a duplicate really of the fax box. This resulted in the error I previously described.

So how does one go about adding that field and the necessary code to update the Membership table?

Gary Darling
  #4 (permalink)  
Old August 8th, 2006, 12:41 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 99
Thanks: 0
Thanked 1 Time in 1 Post
Default

The tools are available under the .NET framework Membership class. You'll find a reference to it in the help files at: ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref12/html/T_System_Web_Security_Membership_Members.htm#Publi cPropertiesToggle

Note that the class has an UpdateUser method that you have to pass a value of class type MembershipUser. The help file reference is:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref12/html/T_System_Web_Security_MembershipUser_Members.htm

The class MembershipUser has an Email property that you can get or set.

With this information, I'm sure that you'll now be on the right track in solving your problem.


  #5 (permalink)  
Old August 8th, 2006, 12:52 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 99
Thanks: 0
Thanked 1 Time in 1 Post
Default

One other thing; The error that you got is most likely becasue you didn't change the profile name Fax in web.config to Email, which is all well and good because all that you would be doing is adding an extra email field to the profile and not changing the email address as you wish.


  #6 (permalink)  
Old August 8th, 2006, 02:58 AM
Registered User
 
Join Date: Aug 2006
Location: Seattle, WA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

MM - Thanks for the tips and the MSDN links, you were right on the money! I spent several hours researching and testing the sample code and finally got all the errors cleaned up. I feel like I crossed over a barrier tonite!

If anyone wants the code I used to add a functioning Update Email field to the UserProfile control, reply to this thread and I'll post it.

Gary
  #7 (permalink)  
Old September 28th, 2006, 10:24 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got round this email problem by creating another email storage which is staored as an extra profile for every user created in an account. If you dont know obout "adding extra profile settings" theres loads of info out there to look out. Anyway heres a solusion for you (VB Code);

In the web config you need to define and setup an extra piece of profile info "EmailEdit" (this info is available on all your web pages and is hardcoded (VS gives you help when typing the code));
</providers>
<properties>
<add name="EmailEdit" type="String"/>
</properties>
</profile>

When the user creates an account we pinch the email address typed in the standard createaccount function that vs2005+ gives us and then add the same email to our "EmailEdit" profile; for example in the "CreateAccount.aspx.vb" under the "continue button click" we could add;

Line1:
Dim EmailEditable As TextBox = CreateUserWizard1.CreateUserStep.ContentTemplateCo ntainer.FindControl("Email")

Line2:
Dim userProfile As ProfileCommon = ProfileCommon.Create(User.Identity.Name, True)

Line3:
Roles.AddUserToRole(User.Identity.Name, "users")

Line4:
userProfile.EmailEdit = EmailEditable.Text

Line5:
userProfile.Save()

So the above saves the email address for each user, now we can access their email anywhere within our site by simply the following

Dim AnyString A String = Profile.EmailEdit
(of course the user must be logged in or we would simply get = "")

We can also change this email address bat anytime by;
Dim NewEmail As String = "JoeBloggs@Hotmail.com"
Profile.EmailEdit = NewEmail

We can also change the the EditEmail value of any of our users without them being logged in by first definng whis user we want to change, to do this call the profile info of a particular user using his/her name first:

Lin1:
Dim userProfile As ProfileCommon = CType(ProfileCommon.Create("TheUserNameAsString", True), ProfileCommon)

Lin2:
userProfile.EmailEdit = "JoeBloggs@Hotmail.com"

Hope this helps, this is just a quick peep at what you can do with user profiles, you can manage things like "user credits" etc.
  #8 (permalink)  
Old September 29th, 2006, 06:58 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: , , .
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to vantoko
Default

garydarling,

I think a lot of people might be interested in this code.
so I'd be happy if you posted it

tnx

koen

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
user profile trouble Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 October 9th, 2007 06:24 PM
Edit user's profile ... Avatar Url: j-parker BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 December 24th, 2006 07:12 PM
user profile creation problem yasminnnnn BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 6 December 11th, 2006 09:13 AM
User Profile edgelogix Pro PHP 1 December 3rd, 2005 04:17 PM
I cannot edit user details hdoldur Classic ASP Databases 0 April 3rd, 2004 10:11 AM



All times are GMT -4. The time now is 02:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.