Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Login Control seems to not post back

Posted on 2010-08-24
3
Medium Priority
?
705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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