Solved

Login Control seems to not post back

Posted on 2010-08-24
3
673 Views
Last Modified: 2013-11-08
I have a login control on my default.aspx page.  User enters usersname and password followed by enter to login.  Page returns back to Default page it doesn't seem as if any of my scripts is being called by the login control.  Why is it not calling any of my code behind scripts?  Any Ideas.
HTML:



<!--Enter login Content Here-->

<asp:Login ID="Login1" runat="server" RememberMeSet="true"

        PasswordRecoveryText="Forget your Password" 

        PasswordRecoveryIconUrl="~/Account/RecoverPassword.aspx" 

        FailureText="Invalid Username or Password" 

        OnLoggedIn="onLoggedInEvent" 

        OnAuthenticate="OnAuthenticationEvent"

        OnLoginError="OnLoginErrorEvent" >

         <LayoutTemplate>

           <table border="0" cellpadding="0" cellspacing="2" width="213">

            <tr>                

                <td align="left" colspan="2" valign="top">

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

                </td>

                <td align="left"  valign="top">

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

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

                     ControlToValidate="UserName" ErrorMessage="Email Address is required." 

                     ToolTip="Email Address is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>

                    </td>

            </tr>

            <tr>

                <td align="left" colspan="2" valign="top">

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

                </td>

                <td align="left" valign="top">

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

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

                     ControlToValidate="Password" ErrorMessage="Password is required." 

                     ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>

                    </td>

            </tr>

            <tr>

                <td colspan="3">

                    <div id="rememberMe">

                        <p><asp:CheckBox ID="RememberMe" runat="server" Text="Remember me" /></p>

                    </div>

                </td>

            </tr>

            <tr>

                <td colspan="3" valign="middle">

                     <!--Take our Login Button if Control does it for you-->

                     <asp:Button runat="server" ID="LoginButton" Text="Sign In" ValidationGroup="Login1" />

                     

                     <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Login1" />

                      <br />

                </td>

            </tr>

            </table> 

       </LayoutTemplate>

</asp:Login>



Code Behind:



Protected Sub onloggingInEvent(ByVal sender As Object, ByVal e As LoginCancelEventArgs) Handles Login1.LoggingIn

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

    End Sub

    Sub OnLoginErrorEvent(ByVal sender As Object, ByVal e As EventArgs)

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

    End Sub

    Sub OnAuthenticationEvent(ByVal sender As Object, ByVal e As EventArgs) Handles Login1.Authenticate

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

    End Sub



    Protected Sub onLoggedInEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn

        Try

            If Not (Request.IsSecureConnection) Then

                changeSSLUrl = ChangetoSecureSite()

            End If

            If Roles.IsUserInRole(Login1.UserName, "Administrator") Or Roles.IsUserInRole(Login1.UserName, "Site Admin") Or Roles.IsUserInRole(Login1.UserName, "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('" + ex.Message.ToString + "');</script>")

        End Try



    End Sub

Open in new window

0
Comment
Question by:Robert Treadwell
  • 2
3 Comments
 

Author Comment

by:Robert Treadwell
ID: 33516765
added the Security section of the web.config file, I don't believe I'm doing any out of the norm, but an extra pair of eyes doesn't hurt.
 <!--

            The <authentication> section enables configuration 

            of the security authentication mode used by 

            ASP.NET to identify an incoming user. 

        -->

    <authentication mode="Forms">

      <forms loginUrl="~/Default.aspx" name=".ASPXFORMSAUTH" cookieless="UseCookies" requireSSL="false" slidingExpiration="false"/>

    </authentication>

    <authorization>

      <allow users="?" />

    </authorization>

    <!--Memeber ship Class -->

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

      <providers>

        <clear/>

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

    <!-- The secure folder is for authenticated and SSL access only. -->

    <!-- Members -->

    <location path="MemberContentPages">

      <system.web>

        <authorization>

          <allow users="*"/>

          <!-- Allow Member & Admins Only-->

          <deny users="?"/>

          <!-- Deny UnAuthenticated Users -->

        </authorization>

      </system.web>

    </location>

    <!-- Admin -->

    <location path="EntityContentPages">

      <system.web>

        <authorization>

          <allow roles="Administrator"/>

          <allow roles="Site Admin"/>

          <allow roles="Assistant"/>

          <!-- Allow Admin Only-->

          <deny users="?"/>

          <deny roles="Member"/>

          <deny roles="Client"/>

          <!-- Deny all other Users -->

        </authorization>

      </system.web>

    </location>

  <system.web>

Open in new window

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33517540
Hi,

Probable Reasons:

(1) Javascript disabled on Browser.

(2) Though I am not well versed with VB but in C# if there is no access specifier is declared it is default private. So might be Line 60 and 63 event handler are private and hence not accessible. Declare them as Protected.

Let us know the result back.

Regards,
V.S.Saini

0
 

Accepted Solution

by:
Robert Treadwell earned 0 total points
ID: 33537799
Removed login control and used backend script.
rotected Sub OnAuthenticationEvent(ByVal sender As Object, ByVal e As EventArgs)

        'e.Authenticated = False

        Try

            If Membership.ValidateUser(UserName.Text, Password.Text) Then

                If Request.QueryString("ReturnUrl") <> "" Then

                    FormsAuthentication.RedirectFromLoginPage(UserName.Text, True)

                Else

                    FormsAuthentication.SetAuthCookie(UserName.Text, True)

                    onLoggedInEvent()

                End If

            Else

                Response.Write("Invalid UserID and Password")

            End If

        Catch ex As Exception

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

        End Try

    End Sub



    Protected Sub onLoggedInEvent()

        Try

            If Not (Request.IsSecureConnection) Then

                changeSSLUrl = ChangetoSecureSite()

            End If

            If Roles.IsUserInRole(UserName.Text, "Administrator") Or Roles.IsUserInRole(UserName.Text, "Site Admin") Or Roles.IsUserInRole(UserName.Text, "Assistant") Then

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

            Else

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

            End If

            Response.Redirect(redirectUrl)

        Catch ex As Exception

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

        End Try



    End Sub



    Protected Sub CreateAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateAccount.Click

        If Not (NewUserLogin.Checked) Then

            Dim strMessage As String = "You must first check the 'New' checkbox to continue Registration."

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

            Exit Sub

        End If

        'Redirect the Url to SSL side of website.



        If Not (Request.IsSecureConnection) Then

            changeSSLUrl = ChangetoSecureSite()



            If loginType.SelectedValue.ToString = "EA" Then

                redirectUrl = changeSSLUrl.ToString.Replace("Default.aspx", "EntityRegistration.aspx")

            ElseIf loginType.SelectedValue.ToString = "ME" Then

                redirectUrl = changeSSLUrl.ToString.Replace("Default.aspx", "Register.aspx")

            End If

            Response.Redirect(redirectUrl)

        End If

    End Sub



    Protected Function ChangetoSecureSite() As String

        Dim secureUrl As String = ""

        Try

            Dim httpsChange As String = Request.Url.ToString().Replace("http:", "https:")

            Dim domainChange As String = httpsChange.Replace("mainDomain", "secureDomain")

            secureUrl = domainChange



        Catch ex As Exception

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

        End Try

        ChangetoSecureSite = secureUrl

    End Function

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

18 Experts available now in Live!

Get 1:1 Help Now