Custom Memberships and Roles Manager as a User Control

Thread is closed for posting
19 posts, 0 answers
  1. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 11 Aug 2007 Link to this post

    Requirements

    RadControls version

    Q1 2007 SP2

    .NET version

    2.0

    Visual Studio version

    VS 2005

    programming language

    VB.NET 2005

    browser support

    all browsers supported by RadControls


     
    PROJECT DESCRIPTION
    On many projects that incorporate Memberships & Roles, it would be nice if you could drop in a user control for handling the administration of users and roles.  This project is for a user control that does exactly that.  It also incorporates some user profile data to make the information more meaningful to look at, and sort.  Namely, it includes the Firstname, Lastname, Company name, and last login date.

    The user control (MembershipManager) displays the data in a radgrid, within a multiview control.  A radtabstrip is used to select the appropriate view, either User Manager or Role Manager.

    The radgrid still allows filtering and sorting on all columns.  The default view is to sort by last login date so that you can quickly see who has most recently logged in.

    The radgrid also incorporates the radcombobox for adding and editing role membership.  Also, it prevents you from attempting to add/edit a user into a role they are already a member of by only displaying the roles the user is not already a member of.

    The project includes a SQL Server 2005 Express database in which I have created 3 users for you to experiment with.  To make life easy, I have also included custom login, create user, change password, and retrieve password pages.  These are in the ~/security folder, and will allow you to create additional users for testing.

    You will need to edit the web.config SMTP information at the bottom in order for the create user wizard to function correctly. 

    If you have problems using the included database files, just delete them.  When you run the project, a new database will be created automatically - so then you just need to create some users using the pages provided in the ~/security folder.

    I have included some screen captures to give you an idea of whats included, and what it looks like.

    If you have any problems using the project, let me know. 

    Regards
    Mark McNeece
    BSolve IT Limited
    http://www.bsolveit.com
  2. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 14 Aug 2007 Link to this post

    Hi Mark,

    Thank you very much for submitting the MembershipManager project in the code library section on our site. This will surely be a solid basis for developers interested in implementing role management for web using RadGrid, RadTabStrip and RadComboBox.
    We really appreciate the time you dedicated to put together the demo along with the snapshots enclosed to this zip archive. Additionally, we are grateful that you will assist other community members giving them advice how to configure/extend the sample.

    Kind regards,
    Stephen Rahnev,
    Technical Support Director, Telerik

    Instantly find answers to your questions at the new Telerik Support Center
  3. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 16 Aug 2007 Link to this post

    I neglected to mention, if you do decide to delete the database in the supplied project or to use your own database, you will need to use the built in ASP.NET Configuration Tool to add at least 1 role called "users".

    Regards
    Mark McNeece.
  4. A28164E1-8ADC-4CA1-89F9-25A246216F79
    A28164E1-8ADC-4CA1-89F9-25A246216F79 avatar
    3 posts
    Member since:
    Jun 2007

    Posted 20 Sep 2007 Link to this post

    you dont have it in c#?


  5. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 20 Sep 2007 Link to this post

    Hello abdul gabier,

    You can convert the code quite easily using our free online code converter:

    http://converter.telerik.com/


    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 20 Sep 2007 Link to this post

    Indeed the code converter is your best bet, but let us know if you get into problems?
  7. 30478D53-0866-4EE1-B302-8A76D30A3C40
    30478D53-0866-4EE1-B302-8A76D30A3C40 avatar
    58 posts
    Member since:
    Oct 2006

    Posted 01 Nov 2007 Link to this post

    I have a question... everythign seems to work great except when the email is sent to the new user it shows up like this:

    Hello <%FirstName%> <%LastName%>!

    A new user account on the <%CompanyName%> website has just been added successfully for you on the Buy Right Sell Right Alaska Web site.

    Your account was set up with the following details:

    Username: usernameOK

    Password: PasswordOK

    To reset your password, you must answer the following question:

    Password Question: <%PasswordQuestion%>

    Password Answer: <%PasswordAnswer%>

    Enjoy!

    The user and pass come through fine but not grabbing the profile info.. any ideas?
     
    Thanks!

  8. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 02 Nov 2007 Link to this post

    Hi SayItFast

    Have you checked your profile settings in your web.config?
    Perhaps you could post the relevant lines of your web.config so that I can check for you?

    Cheers
    Mark
  9. 30478D53-0866-4EE1-B302-8A76D30A3C40
    30478D53-0866-4EE1-B302-8A76D30A3C40 avatar
    58 posts
    Member since:
    Oct 2006

    Posted 02 Nov 2007 Link to this post

    Here is what I have in the config.

    Thanks:

    <membership defaultProvider="SqlMembershipProvider" userIsOnlineTimeWindow="15">

    <providers>

    <clear/>

    <add name="SqlMembershipProvider"

    type="System.Web.Security.SqlMembershipProvider"

    connectionStringName="MembershipConnectionString"

    applicationName="MembershipManager"

    enablePasswordRetrieval="true"

    enablePasswordReset="true"

    requiresQuestionAndAnswer="true"

    requiresUniqueEmail="true"

    passwordFormat="Clear"

    minRequiredPasswordLength="6"

    minRequiredNonalphanumericCharacters="0"/>

    </providers>

    </membership>

    <roleManager enabled="true"

    cacheRolesInCookie="true"

    cookieName=".ASPROLES"

    defaultProvider="SqlRoleProvider">

    <providers>

    <clear/>

    <add connectionStringName="MembershipConnectionString"

    applicationName="MembershipManager"

    name="SqlRoleProvider"

    type="System.Web.Security.SqlRoleProvider"/>

    </providers>

    </roleManager>

    <authentication mode="Forms">

    <forms loginUrl="~/Security/Login.aspx"

    name=".ASPXAUTH"

    protection="Validation"

    timeout="9999999" path="/">

    </forms>

    </authentication>

    <anonymousIdentification enabled="true"/>

    <profile enabled="true"

    defaultProvider="SqlProfileProvider"

    automaticSaveEnabled="true">

    <providers>

    <clear/>

    <add name="SqlProfileProvider"

    type="System.Web.Profile.SqlProfileProvider"

    connectionStringName="MembershipConnectionString"

    applicationName="MembershipManager"/>

    </providers>

    <properties>

    <add name="Firstname" serializeAs="String" allowAnonymous="true"/>

    <add name="Lastname" serializeAs="String" allowAnonymous="true"/>

    <add name="Company" serializeAs="String" allowAnonymous="true"/>

    </properties>

    </profile>

  10. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 02 Nov 2007 Link to this post

    Hmmm... that all looks fine.
    In that case, can you post the ~/security/create-user.aspx.vb code?

    Thanks
    Mark.
  11. 30478D53-0866-4EE1-B302-8A76D30A3C40
    30478D53-0866-4EE1-B302-8A76D30A3C40 avatar
    58 posts
    Member since:
    Oct 2006

    Posted 09 Nov 2007 Link to this post

    Ok I did not have the necessary lines uncommented on the create-user.aspx.vb page however when I do uncomment those lines listed below I get an error.

    Uncoment these lines:

    Dim NoReply As New MailAddress(Session("NoReplyAddress"), Session("CompanyName"))

    e.Message.From = NoReply

    e.Message.Body = e.Message.Body.Replace("<%FirstName%>", Trim(CType(CreateUserWizard1.FindControl("FirstName"), TextBox).Text))

    e.Message.Body = e.Message.Body.Replace("<%LastName%>", Trim(CType(CreateUserWizard1.FindControl("LastName"), TextBox).Text))

    e.Message.Body = e.Message.Body.Replace("<%CompanyName%>", Session("CompanyName"))

    e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", CreateUserWizard1.Question)

    e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", newUser("PasswordAnswer").ToString)


    Now I get the following error:

    Value cannot be null.
    Parameter name: address

    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.ArgumentNullException: Value cannot be null.
    Parameter name: address

    Source Error:

    The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

    1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

      <%@ Page Language="C#" Debug="true" %>

    or:

    2) Add the following section to the configuration file of your application:

    <configuration>
       <system.web>
           <compilation debug="true"/>
       </system.web>
    </configuration>

    Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

    Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: address]
      System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +903327
      System.Net.Mail.MailAddress..ctor(String address, String displayName) +10
      security_create_user.CreateUserWizard1_SendingMail(Object sender, MailMessageEventArgs e) +199
      System.Web.UI.WebControls.CreateUserWizard.OnSendingMail(MailMessageEventArgs e) +105
      System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
      System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571
      System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105
      System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453
      System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149
      System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
      System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
      System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
      System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
      System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
      System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
      System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
    


    The user does get created but the company name etc. are blank.

  12. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 09 Nov 2007 Link to this post

    Can you set debug=true either in the page directive, or in the web.config and run it again, just so that the error information is more specific.

    Cheers
    Mark
  13. 30478D53-0866-4EE1-B302-8A76D30A3C40
    30478D53-0866-4EE1-B302-8A76D30A3C40 avatar
    58 posts
    Member since:
    Oct 2006

    Posted 09 Nov 2007 Link to this post

    Here you go... 

    Value cannot be null.
    Parameter name: address

    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.ArgumentNullException: Value cannot be null.
    Parameter name: address

    Source Error:

    Line 29:         '*********************************************************************************************
    Line 30: 
    Line 31:         Dim NoReply As New MailAddress(Session("NoReplyAddress"), Session("CompanyName"))
    Line 32:         e.Message.From = NoReply
    Line 33:         e.Message.Body = e.Message.Body.Replace("<%FirstName%>", Trim(CType(CreateUserWizard1.FindControl("FirstName"), TextBox).Text))

    Source File: C:\Users\Owner\Documents\Visual Studio 2005\WebSites\Alaska2\Alaska2\Security\create-user.aspx.vb    Line: 31

    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: address]
       System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +904639
       System.Net.Mail.MailAddress..ctor(String address, String displayName) +10
       security_create_user.CreateUserWizard1_SendingMail(Object sender, MailMessageEventArgs e) in C:\Users\Owner\Documents\Visual Studio 2005\WebSites\Alaska2\Alaska2\Security\create-user.aspx.vb:31
       System.Web.UI.WebControls.CreateUserWizard.OnSendingMail(MailMessageEventArgs e) +105
       System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
       System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571
       System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105
       System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453
       System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149
       System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
    
  14. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 09 Nov 2007 Link to this post

    Ahhh!

    I used the session_start event in the global.asax to setup some session variables that I would like be reusing, in this case the session("noreplyaddress").

    You can either set some values via the global.asax as I did, or set exact values in the codebehind page instead of the session variables.

    Cheers
    Mark.
  15. 98BDA500-0CF9-4AF6-ADE4-8226BF90D83A
    98BDA500-0CF9-4AF6-ADE4-8226BF90D83A avatar
    194 posts
    Member since:
    Nov 2002

    Posted 30 Nov 2007 Link to this post

    This was true a great codeexampel and very useful.
    I do miss the editing of the profileinformation in the userAdmin control. ;)
    Bot noone is perfect;)
  16. 3CF44924-D349-404A-A528-085AF2BC59E8
    3CF44924-D349-404A-A528-085AF2BC59E8 avatar
    49 posts
    Member since:
    Aug 2006

    Posted 30 Nov 2007 Link to this post

    lol!

    Yes - your right, that would make it even more useful.  Why not have a go at extending it and post an updated code example?

    Cheers
    Mark.
  17. 16BFF496-3E97-4F33-93C7-86904458C60D
    16BFF496-3E97-4F33-93C7-86904458C60D avatar
    22 posts
    Member since:
    Mar 2005

    Posted 23 Jun 2008 Link to this post

    I'd love to see something like this implemented with Active Directory. Too much on my plate for that at the moment, though. ;)
  18. C3A6E804-E9AF-4C78-AB8C-B7ED2EF11A9F
    C3A6E804-E9AF-4C78-AB8C-B7ED2EF11A9F avatar
    24 posts
    Member since:
    Jul 2012

    Posted 30 Aug 2011 Link to this post

    I'm using ASP.Net Ajax Q3 2009
    I'm converting your MembershipManager to C# and I've run into a few issues:
    I receive the following error:
    Cannot implicitly convert type 'object' to 'System.Collections.ArrayList'
    regarding the line of code: 
    ArrayList UserTable = GetUserTable();
    I've attached the project.
    From
    protected void UserGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                if (!e.IsFromDetailTable)
                {
                    ArrayList UserTable = GetUserTable();
                    this.grid = UserGrid;
                    this.grid.DataSource = UserTable;
                }
            }
     
            private object GetUserTable()
            {
                MembershipUserCollection Users = Membership.GetAllUsers();
                ArrayList UserTable = new ArrayList();
     
                foreach (MembershipUser item in Users)
                {
                    UserDataRow UserRow = new UserDataRow();
                    //UserRow.Firstname = Profile.GetProfile(item.UserName).Firstname;
                    //UserRow.Lastname = Profile.GetProfile(item.UserName).Lastname;
                    //UserRow.Company = Profile.GetProfile(item.UserName).Company;
                    UserRow.Username = item.UserName;
                    UserRow.Email = item.Email;
                    UserRow.LastLoginDate = item.LastLoginDate;
                    UserTable.Add(UserRow);
                }
     
                return UserTable;
            }
  19. 8AE38174-6B24-4267-AEF8-4CA83F09AEF8
    8AE38174-6B24-4267-AEF8-4CA83F09AEF8 avatar
    2 posts
    Member since:
    Apr 2010

    Posted 17 Jul 2013 Link to this post

    I was able to bring this into a C# project and get it to run without errors. However, it only shows the role's Grid. The UserGrid does not show up at all. Its as if it has no data bound to it. Also, although the roles grid shows up and lists the roles it does not list any users under the roles.

    Any ideas?

    Here are the User Management Control Files:
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.