Solved

Login Control seems to not post back

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now