Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Custom Memberships and Roles Manager as a User Control

Custom Memberships and Roles Manager as a User Control

Feed from this thread
  • Posted on Aug 11, 2007 (permalink)

    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
    Attached files

    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Aug 14, 2007 (permalink)

    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

    Reply

  • Posted on Aug 16, 2007 (permalink)

    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.

    Reply

  • SuperCoder avatar

    Posted on Sep 20, 2007 (permalink)

    you dont have it in c#?


    Reply

  • Sebastian Sebastian admin's avatar

    Posted on Sep 20, 2007 (permalink)

    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

    Reply

  • Posted on Sep 20, 2007 (permalink)

    Indeed the code converter is your best bet, but let us know if you get into problems?

    Reply

  • Posted on Nov 1, 2007 (permalink)

    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!

    Reply

  • Posted on Nov 2, 2007 (permalink)

    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

    Reply

  • Posted on Nov 2, 2007 (permalink)

    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>

    Reply

  • Posted on Nov 2, 2007 (permalink)

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

    Thanks
    Mark.

    Reply

  • Posted on Nov 9, 2007 (permalink)

    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.

    Reply

  • Posted on Nov 9, 2007 (permalink)

    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

    Reply

  • Posted on Nov 9, 2007 (permalink)

    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
    

    Reply

  • Posted on Nov 9, 2007 (permalink)

    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.

    Reply

  • Per Holmqvist Master avatar

    Posted on Nov 30, 2007 (permalink)

    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;)

    Reply

  • Posted on Nov 30, 2007 (permalink)

    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.

    Reply

  • Sean Clifford avatar

    Posted on Jun 23, 2008 (permalink)

    I'd love to see something like this implemented with Active Directory. Too much on my plate for that at the moment, though. ;)

    Reply

  • M avatar

    Posted on Aug 30, 2011 (permalink)

    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;
            }

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Custom Memberships and Roles Manager as a User Control