Solved

Login Control seems to not post back

Posted on 2010-08-24
3
680 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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