Troubleshooting the login control?

Last post 11-10-2008 8:39 AM by yrleu. 20 replies.

Sort Posts:

  • Troubleshooting the login control?

    01-02-2006, 8:09 PM
    • Member
      150 point Member
    • bernadou
    • Member since 12-30-2005, 11:34 PM
    • Posts 32

    I’m using a sql2005 db created with aspnet_regsql.exe. and a simple asp.net 2.0 login control and, a passwordRecovery control on the same page.  I can connect to the db using the ASP.NET Configuration tool and add users.  They show up and everything appears OK… but….

     

    When I attempt to use the login control, it returns the standard “unsuccessful” error.  On the same page in the password recovery control, if I enter the user name, it returns the appropriate security question for that user and authenticates the answer and sends the password.

     

    So, I suspect that something is amiss with the login control, but, I’m new to using it, and, am not sure where to begin the troubleshooting process.

     

    Where should I start if I know the username and password I’m entering are correct, yet, they do not authenticate?

     

    Thanks in advance for any assistance.

    Bernie

     

  • Re: Troubleshooting the login control?

    01-08-2006, 12:47 PM
    • Member
      150 point Member
    • bernadou
    • Member since 12-30-2005, 11:34 PM
    • Posts 32

    Ok, since there has been no response to my original post, I'm posting some followup info just in case someone out there can help...

     

    I looked up some information on a custom provider and implemented a very simple custom membership provider based on this article (http://www.devx.com/asp/Article/29256).  It worked great, so I adapted it to use my own SQL 2005 database tables and verified that it worked with them too.  Awesome, I'm on my way...

     

    So, I took this code, and, moved it into an application that I've been struggling with for the last few weeks.

     

    Now, here’s what I observed…

     

    The login control behaves VERY unpredictably.  I can’t personally figure out what is happening.  Worse yet, I haven’t found any documentation on the Login control and what exceptions it might throw so that I might troubleshoot it.  This means I’m left with experimentation.  Can this be true?  Am I just missing something?  Maybe one of the ASP.NET development team can share some of the inner workings of the control’s behavior so that what follows might not happen to others trying to work with the login control.

     

    My story…

    After setting up the web.config file to use my new custom provider and adding my class to the App_Code dir, the page that I had already setup with the drag and drop login control STILL wouldn’t work.  Using debugging I was able to figure out that it wasn't using my provider despite the web.config file telling it it should (it never initialized my object).  So, I moved my web.config file to a brand new empty application on my local web server.  I added a single page to this nice clean application, and dropped the login control on the page.  I copied my class file over.   I didn’t change a single other thing or write even one single line of code…and...  IT WORKED, but Why??

     

    So, I go back into the original little application that has plagued my existence for the last two weeks and…

     

    Added a new page to the application.

    Added the login control to that new page.

    I changed absolutely nothing else....

    And….

    IT WORKED TOO (huh?).  The original page with the login control that wasn’t working still wasn’t working.  So, I just deleted that page and went on my way about trying to be productive with the rest of the project.

     

    Then, again today, and inexplicably (I wasn’t doing any work to the membership stuff), it STOPPED WORKING!!!!  This is driving me crazy.  So, same steps again….

     

    In the same application, with no manual changes to ANY CODE AT ALL, I added a new page, with a fresh login control and IT WORKS!

     

    So, there must be something happening behind the scenes and totally out of my direct control that affects which provider the Login control actually uses (builtin vs. mine) to connect to the data source. 

     

    Please, for the love of all things outdoors (which I’ve seen very little of lately…), someone who understands the inner workings of the Login control, please help shed some light on what is happening here.

     

    Thanks in advance.

    Bernie

  • Re: Troubleshooting the login control?

    01-13-2006, 2:17 PM
    • Participant
      959 point Participant
    • HaoK
    • Member since 07-18-2003, 2:06 PM
    • Posts 185
    • AspNetTeam

    Hi Bernie,

    Sorry for your struggles, so the login control is actually quite simple at its core.  Basically what its doing is taking the UserName and Password which you enter into the text boxes, and eventually calling ValidateUser() with the supplied info on the membership provider you have configured.

    So there's a few ways for you to debug what's going on, you have several events which the login control exposes that you can hook on your page to print out debug information, I'd suggest you try hooking the Authenticate, LoggingIn, and LoginError events.  Also I'd just try verfiying by explicitly calling ValidateUser on your Membership provider with the credentials you are specifying and making sure that it consistently is succeeding. 

    Hope that helps,
    -Hao

  • Re: Troubleshooting the login control?

    01-14-2006, 7:46 AM
    • Member
      150 point Member
    • bernadou
    • Member since 12-30-2005, 11:34 PM
    • Posts 32

    Hao,

    Thanks for your reply.  I really do appreciate it.

    I'm curious at what point ASP.NET decides which provider it will use and what process it uses to make that determination.  I understand that it looks into the web.config, but I'm looking for more precise information regarding the process.  I'm asking because it seems that if you set provider information in web.config it should stick with that, yet, despite the fact that I had provider info in the web.config, some pages with the login control would work, yet some others wouldn't.  How could that be possible?  Worse yet, it never 'broke' so I could see where it was failing, the login control just returned "Your login attempt was not successful" which wasn't any real help.

    I have the authentication portion of the application working, but, I spent a ton of time trying to figure out what was going on with the login control and never truly understood what was happening, so I'm really curious.

    Thanks,

    B

  • Re: Troubleshooting the login control?

    01-16-2006, 3:47 PM
    • Participant
      959 point Participant
    • HaoK
    • Member since 07-18-2003, 2:06 PM
    • Posts 185
    • AspNetTeam

    The login controls all use the MembershipProvider string to determine which provider to use, they access this property right when they are trying to perform the action for the control, so in this case for login, it determines what provider to use by calling Membership.Providers[MembershipProvider] during the processing of the login button click, i.e. when the OnAuthenticate event is raised.

    Hope that helps,
    -Hao

  • Re: Troubleshooting the login control?

    05-03-2006, 1:48 PM
    • Member
      15 point Member
    • stephajn.saunter
    • Member since 05-03-2006, 5:40 PM
    • Edmonton, Alberta
    • Posts 3

    I too am experiencing this same problem.  Although for me, it has never worked right.

    I created my own MembershipProvider class that inherited from Membership Provider.  So...getting on with my story:

    I did a little bit of Response.Write() to get some values.

    The username and password retrieved from the login control was correct, and the MembershipProvider value was set correctly.

    So in the Authenticate event of the Login Control, I did a Response.Write this way:

     

      
    Response.Write("Results from using membership provider explicitly: " & Membership.ValidateUser(Login1.UserName, Login1.Password).ToString & "<br>")

     However, the login control still gives the "Your login attempt was not successful."

    Any thoughts?

    Stephajn

  • Re: Troubleshooting the login control?

    05-03-2006, 1:49 PM
    • Member
      15 point Member
    • stephajn.saunter
    • Member since 05-03-2006, 5:40 PM
    • Edmonton, Alberta
    • Posts 3
    Sorry...forgot to point out that the results of my explicit call to my provider came back as True.
  • Re: Troubleshooting the login control?

    07-01-2006, 3:21 PM
    • Member
      15 point Member
    • danhixon
    • Member since 07-01-2006, 7:17 PM
    • Posts 3
    I am experience this problem too!  VERY FRUSTRATING!

        Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
            If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
                Label1.Text = "user IS valid!"
            End If
            If e.Authenticated Then
                Response.Redirect("admin/managecategories.aspx")
    
            End If
        End Sub

    The login control says "Your login attempt was not successful. Please try again." and my Label1.Text says "user IS valid!"

    False is returned when I try calling FormsAuthentication.Authenticate(Login1.UserName, Login1.Password)   ...

    Any help on this would be GREATLY appreciated!

    -Dan
  • Re: Troubleshooting the login control? (work around)

    07-01-2006, 3:29 PM
    • Member
      15 point Member
    • danhixon
    • Member since 07-01-2006, 7:17 PM
    • Posts 3
    I implemented a work around that seems to work so far:
        Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
            'i don't know why but e.Authenticated is always false so I 
            'have implemented this work around:
            If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, False)
            End If
    
        End Sub
     
    I hope to find out why the login control isn't working for us but until then I'll just use this.
  • Re: Troubleshooting the login control? (work around)

    08-07-2006, 1:59 AM
    • Member
      226 point Member
    • Codescribler
    • Member since 03-10-2006, 6:07 PM
    • Wales UK
    • Posts 98

    AHHHHHHH!

    At least it sounds like I am not alone in this. I had a login control that worked perfectly and then all of a sudden decided to stop. I cant understand what I did or if I did anything to break it. I did some experiments and found that if I created my own two texboxes with a login button and called membership.validateuser it worked - for a time. Because I was testing the admin section I set the login page to login automaticaly. This is important because I know therefore that the User name and Password are correct. I decided it was time to tidy the textboxes up tried to login and it failed! I re-instated the automatic login and it failed but the credentials are definately correct!

    What on earth is going on. Does anyone have a solid work arround or even a solution!

    Danny (going grey rapidly!)

  • Re: Troubleshooting the login control? (work around)

    08-07-2006, 11:06 AM
    • Member
      62 point Member
    • WarrenLong
    • Member since 10-13-2005, 7:59 PM
    • Posts 14

    I also have a similar issue. The login control works fine with VWD.  But it will not login when deployed in IIS. I know it can access the database as it returns the correct security question when I cick Forgot Password.   I am using Windows XP in a network(part of a domain), IIS 5.1.

    Out of curiosity I deployed it (exact copy) on someone else's Windows 2003 machine and it is working there. What could be the problem in the XP machine then? There must be some bug somewhere.......it can access the database but won't authenticate the user.

  • Re: Troubleshooting the login control? (work around)

    08-10-2006, 8:54 AM
    • Member
      5 point Member
    • mandert
    • Member since 08-10-2006, 12:49 PM
    • Posts 1

    Danny,

    did you accidentally clicked twice on the login control in design view? This causes an event to be created like the following:

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
    }

    Delete the event in the Properties window and you should be fine.

    M.

  • Re: Troubleshooting the login control? (work around)

    08-16-2006, 7:36 AM
    • Member
      5 point Member
    • danko
    • Member since 08-16-2006, 11:18 AM
    • Zagreb
    • Posts 1

    Yeah, that's the solution!

    (I've been having problems with it also antil I've read mandert's post.)

    If you wire-up the Authenticate event to your Login control:

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) {... }

    ...the default Authenticate event implemented by the Login control won't fire, so it's authentication check won't work!

    Just remove the Authenticate event from your code and do all the validation/formatting stuff on LoggingIn event, which fires before the authentication.

    Danko

  • Re: Troubleshooting the login control? (work around)

    08-23-2006, 12:23 PM
    • Member
      5 point Member
    • Nyetrogen
    • Member since 08-22-2006, 6:39 PM
    • Posts 1
    Can you explain more about this solution. I've tried for the past 5 days to try and get my app to work on my remote server. From everything that I've read, my configuration is setup properly but I keep getting the generic Login attempt failed message. Maybe provide sample LoggingIn validation that you used. I would really appreciate it. I've looked at this so much that I think I'm just missing something simple. Any help would be much appreciated. I can provide URL or whatever if that would help.
  • Re: Troubleshooting the login control? (work around)

    09-01-2006, 3:41 PM
    • Member
      10 point Member
    • tubugurl
    • Member since 09-01-2006, 7:19 PM
    • Posts 2

    i don't know if this help anyone else, but i was having a hell of a time with the login control also. i had it on a page with the password recovery control using the ActiveDirectoryMembershipProvider. it was working for a few days, then all of the sudden nobody could login. or they could login once, but not again. answering the security question was working fine, so i knew i had a connection to Active Directory. 

    well, after a lot of research it turned out that the "enablePasswordReset=true" in the web.config was the culprit. when i started configuring the CreateUserWizard control for registering new user accounts i had to map the password question, answer, failedpasswordanswercount, etc. to Active Directory attributes and that's when i set "enablePasswordReset" equal true. around that time is when the login control started acting up. sometimes you could login, sometimes you couldn't, some accounts worked and some didn't. the only thing that seems to fix it is if i set "enablePasswordReset" to "false". so we're removing the whole password recovery functionality and writing our own.

    maybe that will save someone else hours of fruitless research.  Super Angry

Page 1 of 2 (21 items) 1 2 Next >