Creating An Account

Last post 09-10-2006 1:10 AM by ScottGu. 9 replies.

Sort Posts:

  • Creating An Account

    07-21-2006, 4:59 PM
    • Member
      610 point Member
    • Al-Obed
    • Member since 02-22-2005, 1:33 PM
    • Posts 122

    Hello Dear;

    I placed the createAccount page into the Admin folder so as to be the lonely person to create accounts, using the CreateUzerWizad control. The wizard creates the accounts successfully so when i go the aspnet_membership pdf file , i can see the new accounts. the problem here when i log in using the newly created accounts, the login fails(no error messages). The logIn form remains displayed.

    Can anybody tell me where is the error here?

    Thanks alot

    VWD2005
  • Re: Creating An Account

    07-22-2006, 1:55 AM
    • Star
      14,543 point Star
    • ScottGu
    • Member since 06-05-2002, 4:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator

    Hi Al-Obed,

    How is the admin folder protected?  What is the value in the <authorization> section of the web.config file?  It could be that you have denied access except to only specific roles -- in which case ASP.NET will automatically redirect the user to a login page if they are not in the role.

    Hope this helps,

    Scott

  • Re: Creating An Account

    07-22-2006, 9:05 AM
    • Member
      610 point Member
    • Al-Obed
    • Member since 02-22-2005, 1:33 PM
    • Posts 122

    Hello Scott;

    During creating an account i assign the role as well (from the list box). The users are created succeefully but the roles are not exceuted by the CreateUerWizard. I wrote the same code that you have in the Video lesson in Membership.

    I am the admin and i want to add users in the Members folders. the code snippet below is what in the Admin/Config. file:

    <?xml version="1.0" encoding="utf-8"?>

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

    <system.web>

    <authorization>

    <allow roles="Administrator" />

    <deny users="*" />

    </authorization>

    </system.web>

    </configuration>


    Thanks

    Alobed

     

    VWD2005
  • Re: Creating An Account

    07-22-2006, 11:52 AM
    • Star
      14,543 point Star
    • ScottGu
    • Member since 06-05-2002, 4:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator

    Hi Alobed,

    I suspect what might be happening is that the user you are creating is not in the "administrator" role -- in which case if they create a user using a createuserwizard page in that folder, they will be redirecte to the login page even if they are already logged in (since this is the default behavior when a role authorization fails).

    Can you add a <asp:loginname> control to the login page and try it again to see if this is indeed happening?  If it is, then what you should find is that the user's login name is displayed when they get redirected back to the login page.  What this means is that the user is logged in, but doesn't have role access to the particular resource.

    Hope this helps,

    Scott

  • Re: Creating An Account

    07-22-2006, 2:53 PM
    • Member
      610 point Member
    • Al-Obed
    • Member since 02-22-2005, 1:33 PM
    • Posts 122

    Hello Scott;

    thanks for reply. as i mentioned in the earlier posts, i am the adminstrator who create users or accounts not them. I createm them them assign them roles (Members). When i open the asp.net configuration i can see the users are added, but "Without  assigning them access to roles (i assign them members role". when i assign them a role through asp.net configuration it works fine. I think the problem here is that the code in the script is not fired.

    i s it possible to test the code if it is running or not?

    This is the script code:

    <%

    @ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="CreateAccount.aspx.vb" Inherits="CreateAccount" title="Untitled Page" %>

    <

    script runat="server">

    Public Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)

    ListBox1.DataSource = Roles.GetAllRoles()

    ListBox1.DataBind()

    End Sub

    Public Sub DeactivateStep(ByVal sender As Object, ByVal e As System.EventArgs)

    Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)

    End Sub

    </

    script>

    Regards

    Al-0bed

    VWD2005
  • Re: Creating An Account

    07-22-2006, 2:55 PM
    • Member
      610 point Member
    • Al-Obed
    • Member since 02-22-2005, 1:33 PM
    • Posts 122

    Hello Scott;

    thanks for reply. as i mentioned in the earlier posts, i am the adminstrator who create users or accounts not them. I createm them them assign them roles (Members). When i open the asp.net configuration i can see the users are added, but "Without  assigning them access to roles (i assign them members role". when i assign them a role through asp.net configuration it works fine. I think the problem here is that the code in the script is not fired.

    i s it possible to test the code if it is running or not?

    This is the script code:

    <%

    @ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="CreateAccount.aspx.vb" Inherits="CreateAccount" title="Untitled Page" %>

    <

    script runat="server">

    Public Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)

    ListBox1.DataSource = Roles.GetAllRoles()

    ListBox1.DataBind()

    End Sub

    Public Sub DeactivateStep(ByVal sender As Object, ByVal e As System.EventArgs)

    Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)

    End Sub

    </

    script>

    Regards

    Al-0bed

    VWD2005
  • Re: Creating An Account

    07-24-2006, 3:01 AM
    • Star
      14,543 point Star
    • ScottGu
    • Member since 06-05-2002, 4:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator

    Hi Al-Obed,

    The problem you have above is that you are logged in as the administrator when you are creating the account.  As such, in the code above you are adding yourself to the roles as opposed to the new user(since User.Identity.Name will resolve to you as opposed to the newly created account).  You should instead use the CreateUserWizard's UserName property to retrieve the name of the newly created user when called Roles.AddUserToRole above.

    Also, make sure you have you set the "LoginCreatedUser" property to the CreateUserWizard control to false.  If not, then when you as an admin create the account, it will auto-log you in as the new user. Instead, you probably want to stay logged in as yourself.

    Hope this helps,

    Scott

  • Re: Creating An Account

    07-24-2006, 8:56 AM
    • Member
      610 point Member
    • Al-Obed
    • Member since 02-22-2005, 1:33 PM
    • Posts 122

    Thanks Scott;

    It is great. It really worked out

    VWD2005
  • Re: Creating An Account

    09-08-2006, 9:38 AM
    • Member
      25 point Member
    • da blockxzzz
    • Member since 09-04-2006, 9:58 PM
    • Posts 5

    Hi

    I've tried to do the same but how do you use the CreateUserWizard's UserName property to retrieve the name of the newly created user when called Roles.AddUserToRole above, cause I can't figure it out.


    Steffan 

     

     

  • Re: Creating An Account

    09-10-2006, 1:10 AM
    • Star
      14,543 point Star
    • ScottGu
    • Member since 06-05-2002, 4:36 PM
    • Redmond, WA
    • Posts 2,004
    • AspNetTeam
      Moderator

    Hi Steffan,

    Assuming your CreateUserWizard control is named "CreateUserWizard1", then you could write code like this:

        Roles.AddUsertoRole(CreateUserWizard1.UserName, "adminrole")

    Hope this helps,

    Scott

    P.S. Typically you'd want to-do this in the CreatedUser event.

Page 1 of 1 (10 items)