ASP.Net按钮不会在一组情况下回发

时间:2014-12-18 11:04:50

标签: asp.net vb.net

这是我遇到的最奇怪的错误。我创建了一个模板网站,其中包含一个登录页面。如果您在第一次加载时直接进入登录页面,该按钮不会回发,实际上它什么都不做,只是坐在那里看起来很茫然。但是,如果您首先访问任何其他页面并重定向(因为个人尚未登录),它可以正常工作。

这种情况发生在IE上,但我还没有在其他浏览器上尝试,因为这是内部网的一部分,我们的系统只使用IE8。我还尝试将UseSubmitBehaviourCausesValidation设置为false,但这没有效果。

我还没有发布所有代码,因为涉及多个页面,所以我对所涉及的页面进行了基本描述

母版页

普通母版页,提供一般布局和样式

的BasePage

应用程序中的所有页面都继承此页面。确保根据用户的设置应用正确的主题/品牌。还要检查以确保用户已登录,如果用户未知,它将针对特定页面将其重定向回登录页面。

Simplelogon.aspx

仅用于处理登录过程的页面。代码

ASPX文件

<asp:Content ID="Content5" ContentPlaceHolderID="cphContent" runat="server">
<asp:UpdatePanel ID="upContainer" runat="server">
    <ContentTemplate>
        <asp:UpdatePanel ID="pLogon" runat="server">
            <ContentTemplate>
                <div style="width: 400px; height: 180px; left: 50%; top: 50%; margin-top: -100px; margin-left: -210px; position: fixed; z-index: 101; background-color: #eee; padding: 0px; border: 2px solid #000; text-align: center; padding: 10px;">
                    <span style="font-weight: bold; font-size: 18pt">Welcome</span>
                    <table width="100%" border="0" cellpadding="0" cellspacing="10">
                        <tr>
                            <td align="center"><b>User ID</b></td>
                            <td align="center"><b>Password</b></td>
                        </tr>
                        <tr>
                            <td align="center">
                                <asp:TextBox ID="userID" runat="server" TextMode="SingleLine" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1"></asp:TextBox><br />
                                <span style="font-size: 8pt">&nbsp;</span>
                            </td>
                            <td align="center">
                                <asp:TextBox ID="password" runat="server" TextMode="Password" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1"></asp:TextBox> <br /> 
                                <a href="userReset.aspx" style="font-size: 8pt">[Forgot Password]</a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <asp:CheckBox ID="cbRememberMe" runat="server" Text="Remember Me" /><br />
                                <asp:Button ID="logon" runat="server" Text="Logon" /></td>
                        </tr>
                    </table>
                    <asp:Literal ID="litLogonMessage" runat="server"></asp:Literal>

                    <div style="position: absolute; top: 0px; right: 5px; font-size: 8pt; margin-top: -90px; display: block;">
                        <a href="UserRegister.aspx">[register]</a>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ContentTemplate>
</asp:UpdatePanel>

VB页面提取

    Private Sub logon_Click(sender As Object, e As EventArgs) Handles logon.Click
    If Not (String.IsNullOrEmpty(userID.Text) Or String.IsNullOrEmpty(password.Text)) Then
        Dim sqlParameters As New List(Of SqlClient.SqlParameter)
        SQLDB.addParameterToList(sqlParameters, "@PUID", userID.Text)
        Dim salt As String = SQLDB.fetchSingleValue("SELECT salt FROM Users WHERE PUID = @PUID", adminDB, sqlParameters)
        Dim strSQL As String = "SELECT UserID FROM WebApplication A INNER JOIN Permissions P ON A.ApplicationID = P.FkApplication INNER JOIN Users U ON P.FkUser = U.UserID WHERE PUID = @PUID AND Password2 = @Password AND ((A.ApplicationCode = @AppCode AND P.Locked = 0) OR U.AppsDev = 1)"
        Dim rP As String = varSession("ReturnPath")
        Dim appCode As String
        If fqAppPath.IndexOf("localhost") = -1 Then
            appCode = varSession("CallingApplication", "Global")
        Else
            appCode = SiteCode
        End If
        sqlParameters.Clear()
        SQLDB.addParameterToList(sqlParameters, "@PUID", userID.Text)
        SQLDB.addParameterToList(sqlParameters, "@Password", fetchHash(password.Text, salt))
        SQLDB.addParameterToList(sqlParameters, "@AppCode", appCode)
        Dim result As String = SQLDB.fetchSingleValue(strSQL, adminDB, sqlParameters)

        If IsNumeric(result) Then
            varSession("UserName", "Global") = userID.Text
            varSession("UserID", "Global") = result
            strSQL = "SELECT AppsDev, PasswordExpires FROM Users WHERE UserID = @UserID"
            sqlParameters.Clear()
            SQLDB.addParameterToList(sqlParameters, "@UserID", result)
            Dim dt As DataTable = SQLDB.fetchMultipleValues(strSQL, adminDB, sqlParameters)
            If Convert.ToBoolean(dt.Rows(0).Item("AppsDev")) Then
                varSession("AppsDev", "Global") = True
            Else
                varSession("AppsDev", "Global") = False
            End If

            Dim sql As String = ""
            Dim myCookies As New GenericCookie()

            myCookies.setRememberMeCookie(cbRememberMe.Checked)
            myCookies.SetCookies(varSession("UserID", "Global"), varSession("UserName", "Global"))
            sql = "UPDATE Permissions SET LastUsed = current_timestamp WHERE FkUser = " & varSession("UserID", "Global") & " AND FkApplication IN (SELECT ApplicationID FROM WebApplication WHERE ApplicationCode = '" & appCode & "')"
            SQLDB.executeSqlCUD(sql, adminDB)

            If dt.Rows(0).Item("PasswordExpires") < Now Then
                Dim newPassword As String = generatePassword()
                Dim newSalt As String = generatePassword()
                Dim newHash As String = fetchHash(newPassword, newSalt)
                Dim newDate As DateTime = Now.AddMonths(6)

                sql = "UPDATE Users (Password2, Salt, PasswordExpires, PasswordExpired) VALUES ('" & newHash & "', '" & newSalt & "', '" & newDate & "', 0) WHERE UserID = '" & result
                SQLDB.executeSqlCUD(sql, adminDB)

                litNewPassword.Text = newPassword
                pLogon.Visible = False
                pChangePassword.Visible = True

            Else

                If String.IsNullOrEmpty(rP) Then
                    Response.Redirect("default.aspx")
                Else
                    Response.Redirect(rP)
                End If
            End If

        Else
            password.Text = Nothing
            litLogonMessage.Text = "Unable to verify your credentials.<br />Please check your User ID and re-enter your password to try again"
            varSession("FailedLogons", "Global") = varSession("FailedLogons", "Global") + 1
            If varSession("FailedLogons", "Global") > 3 Then
                Response.Redirect("/accessdenied.aspx"))
            End If
        End If
    Else
        If String.IsNullOrEmpty(userID.Text) Then
            userID.BorderColor = Drawing.Color.Red
            userID.BorderStyle = BorderStyle.Solid
            userID.BorderWidth = 2
        Else
            userID.BorderColor = Drawing.Color.Silver
            userID.BorderStyle = BorderStyle.Solid
            userID.BorderWidth = 1
        End If
        If String.IsNullOrEmpty(password.Text) Then
            password.BorderColor = Drawing.Color.Red
            password.BorderStyle = BorderStyle.Solid
            password.BorderWidth = 2
        Else
            password.BorderColor = Drawing.Color.Silver
            password.BorderStyle = BorderStyle.Solid
            password.BorderWidth = 1
        End If
        litLogonMessage.Text = "<span style=""color: #f00"">Please enter your User ID <b>and</b> password to continue</span>"
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

我发现它是什么,我基本上是在脚下射击自己。该页面正在回发,但由于系统中的某些代码更深入,因此它直接通过并且什么都不做。

感谢那些帮助我走上正确道路的人