Getting account created date anf logged on date in Profiles

Last post 09-22-2008 12:43 PM by ArminStockner. 7 replies.

Sort Posts:

  • Getting account created date anf logged on date in Profiles

    09-21-2008, 1:17 PM
    • Member
      237 point Member
    • amereto2k
    • Member since 01-30-2006, 4:31 PM
    • Posts 386

    Hi

    I am using profiles and on MyProfile.aspx page, i want to show the date the user created their account

    and the last time they logged on.

    Also I want to get the users birthdate. I know i can declare a type of  datetime in Webconfig but not sure

    what are the best controls to put on the page so the user can enter this detail. Dropdown list maybe.

    I am extending the create user wizard to get the extra profile data.

     grateful for any examples in  in Charp

     amereto

  • Re: Getting account created date anf logged on date in Profiles

    09-21-2008, 2:10 PM
    Answer
    • Contributor
      2,017 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 2:18 AM
    • Germany, Bavaria
    • Posts 373

     With the MembershipUser class you will get all these information you need. Just load it like in this page:

    http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.aspx

    Afterwards you have to save the values to profiles:

    http://www.odetocode.com/articles/440.aspx

    If you need a code sample I will write you a small one

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Getting account created date anf logged on date in Profiles

    09-21-2008, 3:18 PM
    • Member
      237 point Member
    • amereto2k
    • Member since 01-30-2006, 4:31 PM
    • Posts 386

    yes if you could write some c sharp code to put me on track be very useful.

    thanks

     

  • Re: Getting account created date anf logged on date in Profiles

    09-21-2008, 5:26 PM
    • Contributor
      2,017 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 2:18 AM
    • Germany, Bavaria
    • Posts 373

     So this should be a working code but I didn't have time to test it. I put an login control on my site with the authenticate event automatically created by the control:

      protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            MembershipUser user = Membership.GetUser(Login1.UserName);
            Profile.Profile1 = user.CreationDate.ToString();
            Profile.Profile2 = user.LastActivityDate.ToString();
            Profile.Save();   

         }

    In order to use the profile you have to declare them in web.config like this:

       <profile >
            <properties>
              <add name="Profile1" allowAnonymous="true" />
              <add name="Profile2" allowAnonymous="true"/>
            </properties>
          </profile>

     

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Getting account created date anf logged on date in Profiles

    09-21-2008, 8:24 PM
    • Member
      237 point Member
    • amereto2k
    • Member since 01-30-2006, 4:31 PM
    • Posts 386

    hi,

    I got the following error?

     

    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.Configuration.Provider.ProviderException: This property cannot be set for anonymous users.

    Source Error:

    Line 58:         }
    Line 59:         set {
    Line 60:             this.SetPropertyValue("Profile1", value);
    Line 61:         }
    Line 62:     }

     

     code behindprotected void Login1_Authenticate(object sender, AuthenticateEventArgs e)

    {

    MembershipUser user = Membership.GetUser(Login1.UserName);

    Profile.Profile1 = user.CreationDate.ToString();

    Profile.Profile2 = user.LastActivityDate.ToString();

    Profile.Save();

    }

     

     In web config - I dont allow allow Anonymous users on the site so I put that bit to false

    <add name="Profile1" type="System.String" allowAnonymous="false"/>

    <add name="Profile2" type="System.String" allowAnonymous="false"/>

  • Re: Getting account created date anf logged on date in Profiles

    09-22-2008, 10:02 AM
    • Contributor
      2,017 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 2:18 AM
    • Germany, Bavaria
    • Posts 373

     Yeah with this code you have to be locked in because the profiles are saved under your specific user. If you also want so save the profile anonymous you have to add some additional code.

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Getting account created date anf logged on date in Profiles

    09-22-2008, 10:27 AM
    • Member
      237 point Member
    • amereto2k
    • Member since 01-30-2006, 4:31 PM
    • Posts 386

    Hi,

    thats the error I get when logged im thought.

    can that be right?

  • Re: Getting account created date anf logged on date in Profiles

    09-22-2008, 12:43 PM
    Answer
    • Contributor
      2,017 point Contributor
    • ArminStockner
    • Member since 09-19-2006, 2:18 AM
    • Germany, Bavaria
    • Posts 373

     Hi,

    I think you will find your solution right here:

    http://forums.asp.net/p/1225752/2199107.aspx

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
Page 1 of 1 (8 items)