Solved

asp.net validateuser failure

Posted on 2010-09-01
1
337 Views
Last Modified: 2012-05-10
On my site I am able to register a user using createuserwizard with the setting 'LoginCreatedUser' set to true.  All of this is done successfully.  When I log the user out and use the login control to log user back in.  I am unable to authenticate users.  Continually receive a Failure Message.

I'm using Membership to CreateUser and to ValidateUser but something is being capture differently.  When I'm capturing the username and password fields how are these values compared to data stored in aspnet_Membership table?
HTML:



<asp:Login ID="RMELogin" runat="server" Enabled="true" DisplayRememberMe="true" 

                    FailureText="Login failed please try again.  If problem continues please see Site Admin." 

                    LoginButtonText="Sign In" MembershipProvider="SqlProvider"

                    RememberMeSet="true" UserNameLabelText="Username:" TextBoxStyle-Width="120px"

                    UserNameRequiredErrorMessage="Username is required" TitleText="" 

                    PasswordRequiredErrorMessage="Password is Requird." 

                    Font-Bold="true" ForeColor="White" OnAuthenticate="onAuthenticatedEvent" OnLoggedIn="onLoggedInEvent">

                        <LayoutTemplate>

                            <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">

                                <tr>

                                    <td>

                                        <table cellpadding="0">

                                            <tr>

                                                <td align="right">

                                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>

                                                </td>

                                                <td>

                                                    <asp:TextBox ID="UserName" runat="server" Width="120px"></asp:TextBox>

                                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 

                                                        ControlToValidate="UserName" ErrorMessage="Username is required" 

                                                        ToolTip="Username is required" ValidationGroup="ctl09$RMELogin">*</asp:RequiredFieldValidator>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td align="right">

                                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>

                                                </td>

                                                <td>

                                                    <asp:TextBox ID="Password" runat="server" TextMode="Password" Width="120px"></asp:TextBox>

                                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 

                                                        ControlToValidate="Password" ErrorMessage="Password is Requird." 

                                                        ToolTip="Password is Requird." ValidationGroup="ctl09$RMELogin">*</asp:RequiredFieldValidator>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td colspan="2">

                                                    <asp:CheckBox ID="RememberMe" runat="server" Checked="True" 

                                                        Text="Remember me next time." />

                                                </td>

                                            </tr>

                                            <tr>

                                                <td align="center" colspan="2" style="color:Red;">

                                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>

                                                </td>

                                            </tr>

                                            <tr>

                                                <td align="right" colspan="2">

                                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Sign In" 

                                                        ValidationGroup="ctl09$RMELogin" />

                                                </td>

                                            </tr>

                                        </table>

                                    </td>

                                </tr>

                            </table>

                        </LayoutTemplate>

                        <TextBoxStyle Width="120px" />

                    </asp:Login>



ASPX:

 Protected Sub onAuthenticatedEvent(ByVal sender As Object, ByVal e As EventArgs)

        Dim userNameTB As TextBox = CType(LoginView1.FindControl("RMELogin").FindControl("UserName"), TextBox)

        Dim passwordTB As TextBox = CType(LoginView1.FindControl("RMELogin").FindControl("Password"), TextBox)



        Try

            If Not (Membership.ValidateUser(userNameTB.Text, passwordTB.Text)) Then

                ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('Authentication Fail.');</script>")

            End If

        Catch ex As Exception

            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('" + ex.Message + "');</script>")

        End Try





    End Sub



    Protected Sub onLoggedInEvent(ByVal sender As Object, ByVal e As EventArgs)

        ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('Inside Logged In');</script>")

        Dim userNameTB As TextBox = CType(LoginView1.FindControl("RMELogin").FindControl("UserName"), TextBox)

        Dim passwordTB As TextBox = CType(LoginView1.FindControl("RMELogin").FindControl("Password"), TextBox)

        Try

            If Not (Request.IsSecureConnection) Then

                changeSSLUrl = ChangetoSecureSite()

            End If



            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('" + User.Identity.Name + "');</script>")

            If Roles.IsUserInRole(User.Identity.Name, "Administrator") Or Roles.IsUserInRole(User.Identity.Name, "Site Admin") Or Roles.IsUserInRole(User.Identity.Name, "Assistant") Then

                redirectUrl = changeSSLUrl.ToString.Replace("Default.aspx", "RME/EntityContentPages/EntityHome.aspx")

            Else

                redirectUrl = changeSSLUrl.ToString.Replace("Default.aspx", "RME/MemberContentPages/MemberHome.aspx")

            End If



            Response.Redirect(redirectUrl)

        Catch ex As Exception

            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('onLoggedInEvent produce the following error:\n" + ex.Message + "');</script>")

        End Try



    End Sub



web.config

 <!--

            The <authentication> section enables configuration 

            of the security authentication mode used by 

            ASP.NET to identify an incoming user. 

        -->

    <authentication mode="Forms">

      <forms defaultUrl="~/Default.aspx" protection="All" name=".ASPXFORMSAUTH" loginUrl="Default.aspx" slidingExpiration="false"  timeout="10" requireSSL="true"

        cookieless="UseCookies" />

    </authentication>

    <!-- This section denies access to all files in this application except for those that you have not explicitly specified by using another setting. -->

    <authorization>

      <deny users="?" />

    </authorization>

    <!-- Set HttpCookie's: this setting indicates whether SSL is required-->

    <httpCookies requireSSL="true" />

    <!--Since the 'protection' variable in the Forms tag is set to 'All' then we must set the Machine Key parameters Validation Key to SHA1 -->

    <machineKey validationKey="AutoGenerate" validation="SHA1"/>    

    <!--Memeber ship Class -->

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

      <providers>

        <remove name="AspNetSqlProvider" />

        <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="rmeaspnetdbConnectionString" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed"/>

      </providers>

    </membership>

    <!--Role Management goes here-->

    <roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieProtection="All">

      <providers>

        <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="rmeaspnetdbConnectionString"

             applicationName="/" />

      </providers>

    </roleManager>

  </system.web> <!-- Closing System.web inorder to apply location tags -->



  <!-- This section gives the unauthenticated user access to the Default.aspx page only. It is located in the same folder as this configuration file. -->

  <location path="Default.aspx">

    <system.web>

      <authorization>

        <allow users ="*" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the unauthenticated user access to all Account Pages. -->

  <location path="Account">

    <system.web>

      <authorization>

        <allow users ="*" />

      </authorization>

    </system.web>

  </location>

  <location path="ChangePassword.aspx">

    <system.web>

      <authorization>

        <deny users ="?" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the authenticated user access to all of the files that are stored in the Member Content Pages folder.  -->

  <location path="MemberContentPages">

    <system.web>

      <authorization>

        <deny users ="?" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the authenticated user with Role Administrator, Site Admin and Assistant access to all of the files that are stored in the Entity Content Pages folder.  -->

  <location path="EntityContentPages">

    <system.web>

      <authorization>

        <deny users ="?" />

        <deny roles = "Member" />

        <deny roles = "Client" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the authenticated user access to all of the files that are stored in the Content Pages folder.  -->

  <location path="ContentPages">

    <system.web>

      <authorization>

        <deny users ="?" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives authentication to the Administrator role only all of files stored in the Admin Pages folder.  -->

  <location path="AdminPages">

    <system.web>

      <authorization>

        <deny users ="?" />

        <allow roles = "Adminstrator" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the unauthenticated users access to All RME Application.  -->

  <location path="Applications">

    <system.web>

      <authorization>

        <allow users = "*" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives the unauthenticated users access to Scrapbook introduction page.  -->

  <location path="Scrapbook">

    <system.web>

      <authorization>

        <allow users = "*" />

      </authorization>

    </system.web>

  </location>

  <!-- This section gives authenticated users access to Editor and Slideshow.  -->

  <location path="ScrapBookEditor.aspx">

    <system.web>

      <authorization>

        <deny users = "?" />

      </authorization>

    </system.web>

  </location>

  <location path="ScrapbookSlideShow.aspx">

    <system.web>

      <authorization>

        <deny users = "?" />

      </authorization>

    </system.web>

  </location>

  <system.web>  <!-- Re-Open System.web from previous closing  -->

Open in new window

0
Comment
Question by:Robert Treadwell
1 Comment
 

Accepted Solution

by:
Robert Treadwell earned 0 total points
Comment Utility
I originally did not set e.Authenticated to True, added code all works well.


if Memebership.ValidateUser(username, password) then

          e.Authenticated = True

End If

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now