[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Login Control seems to not post back

Posted on 2010-08-24
3
Medium Priority
?
723 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses

590 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