Giving approval to site postings

Last post 04-24-2008 1:23 PM by PcolaBob. 22 replies.

Sort Posts:

  • Re: Giving approval to site postings

    04-23-2008, 12:37 PM
    • Loading...
    • PcolaBob
    • Joined on 01-25-2007, 8:33 AM
    • Posts 59

    Thank you soooooooooooo much!!

    I don't want to generate the email with the approval link.  My situation is that I'm doing a web site for a Yahoo group that I run.  So, I will manually check to see if they are members of the Yahoo group, and then approve them or not, based on that.  I don't want anyone who is not a member of the group to have access to the members only area of this new website.

    Thanks again!

     Bob

  • Re: Giving approval to site postings

    04-23-2008, 1:54 PM
    • Loading...
    • ashmetry
    • Joined on 09-26-2007, 7:30 PM
    • Houston, TX
    • Posts 274

    Glad I was able to help :).. Dont forget to mark the question as answered.

    -Ash
    Web:   www.love2trade.com
    Blog:   blog.love2trade.com

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Giving approval to site postings

    04-24-2008, 1:43 AM
    • Loading...
    • PcolaBob
    • Joined on 01-25-2007, 8:33 AM
    • Posts 59

    ashmetry:

    Ok, here is my 2 cents..

    I have not implemented the membership approval just yet...however it can easily be implemented by:

    1. In Register.aspx.cs|vb, after the user is created you can set the IsApproved to false

    protected void CreateUserWizardControl_CreatedUser(object sender, EventArgs e){
    ...
          Membership.GetUser().IsApproved=false;   //this will return the current logged in user

    }

    Ash,

    I tried to implement exactly what you posted above.  Here's what I did:

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

    Membership.GetUser.IsApproved = False

    End Sub

    When I ran it, I got this error:

    System.NullReferenceException was unhandled by user code
      Message="Object reference not set to an instance of an object."
      Source="App_Web_y1c5uvrz" 

    ThaT's like the old 429 Automation Errors in VB6 whien you forgot to set a reference to something.  I thought the references to the Membership provider were set by using the Membership controls (Login, Create User, etc.) What else do I need to do?  The register.aspx page is in the root of the application, so it's not a folder problem.

    I also tried taking out the 1 after CreateUserWizard, but it didn't make any difference.  It's the line referenceing the Membership class that causes the error.  I also tried putting in curly brackets since you had them in yours, but I'm using VB and it gave me a syntax error. :)  

    Thanks for your help,

     Bob

     

  • Re: Giving approval to site postings

    04-24-2008, 10:03 AM
    • Loading...
    • ashmetry
    • Joined on 09-26-2007, 7:30 PM
    • Houston, TX
    • Posts 274

    Are you sure its Membership.GetUser.IsApproved = False and not Membership.GetUser().IsApproved = False

    ?? I know nothing about VB...I HATE that language :)

    null reference is executed if you call a method or a property on a null object. You need to tell the UserWizard control to call the CreateUserWizard1_CreatedUser method on the CreatedUser event. So make sure that this event is set correctly, the name of the method doesnt mater as long as its the same....

    CreatedUser="foobar"

    Protected Sub foobar(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

    Membership.GetUser().IsApproved = False

    End Sub

    -Ash
    Web:   www.love2trade.com
    Blog:   blog.love2trade.com

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Giving approval to site postings

    04-24-2008, 11:11 AM
    • Loading...
    • PcolaBob
    • Joined on 01-25-2007, 8:33 AM
    • Posts 59

    ashmetry:

    ?? I know nothing about VB...I HATE that language :)

    OUCH!  That hurt!  You really know how to wound an old VB guy!  LOL!!!

    ashmetry:

    Are you sure its Membership.GetUser.IsApproved = False and not Membership.GetUser().IsApproved = False

    null reference is executed if you call a method or a property on a null object. You need to tell the UserWizard control to call the CreateUserWizard1_CreatedUser method on the CreatedUser event. So make sure that this event is set correctly, the name of the method doesnt mater as long as its the same....

    CreatedUser="foobar"

    Protected Sub foobar(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

    Membership.GetUser().IsApproved = False

    End Sub

    OK, I put the Open and Close parenthesis after the Method Call:

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser

    Membership.GetUser().IsApproved = False

    End Sub

    But, it made no difference.:It's the Membership.GetUser().IsApproced = False line that fails, and is highlighed in yellow when it comes up.

    Thanks so much for your input.  I appreciate it... even if you do hate VB. :)

     Bob

     

  • Re: Giving approval to site postings

    04-24-2008, 11:38 AM
    • Loading...
    • ashmetry
    • Joined on 09-26-2007, 7:30 PM
    • Houston, TX
    • Posts 274

    LOL...

    actually try using OnCreatingUser event instead of OnCreatedUser 

     and use Membership.GetUser(CreateUserWizard1.UserName).IsApproved=False;

    check http://forums.asp.net/p/939408/1119989.aspx it talks more about why Membership.GetUser() could return a null..which is why you are getting the nullexception...

    also http://msdn2.microsoft.com/en-us/library/fcxcb339.aspx is the documentation for the GetUser() Method....

     See if that works for u

    -Ash
    Web:   www.love2trade.com
    Blog:   blog.love2trade.com

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Giving approval to site postings

    04-24-2008, 1:05 PM
    • Loading...
    • PcolaBob
    • Joined on 01-25-2007, 8:33 AM
    • Posts 59

    Ash, and others,

    EUREKA!!!  I worked it out.  THANKS for all your help. When I was first learning VB (sorry, Ash :) ) my instructor, and best friend to this day used to tell me every time I'd go to him with a question about something, "Go write an app that uses it.  When you figure it out, no one can ever take it from you."  It used to make me so frustrated, but he was right.  When I finally figured the darn thing out, and got it working, I knew it. 

    Well, this has gone is a very similar direction.  In looking at the links you sent me, I realized that perhpas I was going about this all wrong.  And in fact I was.  The GetUser() Method ONLY EVER works with a logged in User, which someone who is creating a new account will not be.  So, I stepped back from the Membership methods and started researching the CreateUserWizard properties and methods.  Here's what I came up with:

     Protected Sub CreateUserWizard1_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser

    CreateUserWizard1.DisableCreatedUser =True CreateUserWizard1.LoginCreatedUser = False

    End Sub

    And it works like a charm!!!  It disables the user, unil I can approve them, and it stops the Wizard from logging them in. Now, I've just got to make me a way to enable them, but that should be easy.  I'll try to find the flg in the database that marks them as disabled and clear it when I approve them.  It appears that  it may be the Approved field, but not sure.  I'll work on that next. 

    But if anyone is wanting to not automatically approve new registerees, these two lines of code work great!

    Thanks for everyone's patience and help,

    Bob

  • Re: Giving approval to site postings

    04-24-2008, 1:23 PM
    • Loading...
    • PcolaBob
    • Joined on 01-25-2007, 8:33 AM
    • Posts 59

    One quick follow-up:  It is the "IsApproved" field in the Membership database that will need to be reset once you want to approve the registeree.  The code I used above sets the field to False.  Changing it to true allows them to log in just fine.  I tested it.

    Thakns again,

    Bob

Page 2 of 2 (23 items) < Previous 1 2