大家好!这是我的处女作,请大家不要见笑 大家都认为用户登入程序是个很简单的验证程序,其实不然,里面有很多要注意的东西。 代码如下: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load bAlertCookie.Value = "0" Response.Cookies.Add(bAlertCookie) End Sub
Public Function Te_Change(ByVal strTextF As String) As String Dim strTextL As String strTextL = StrConv(strTextF, VbStrConv.Narrow) Return strTextL End Function
Private Sub cmdEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnter.Click Dim str As String = "Provider=OraOLEDB.Oracle.1;User ID=kinei;Data Source=JTECSDB;Extended Properties=;Persist Security Info=True;Password=123" txtmemberNo.Text = Te_Change(txtmemberNo.Text) txtPassword.Text = Te_Change(txtPassword.Text) Dim strSQL As String = "Select * From TEST where ID= '" & txtmemberNo.Text & "'" Dim conn As New OleDbConnection(str) Dim strshow As String = " password err" Dim str2show As String = "id err" Dim check As Boolean Dim i As String check = IsNumeric(txtmemberNo.Text) If txtmemberNo.Text <> "" And txtPassword.Text <> "" Then If check = True Then Try conn.Open() Dim cmd As New OleDbCommand(strSQL, conn) Dim myReader As OleDbDataReader = cmd.ExecuteReader() myReader.Read() If myReader.HasRows Then If txtPassword.Text = myReader("PASSWORD") Then bAlertCookie.Value = "0" Response.Redirect("ok.aspx") Else
bAlertCookie.Value = "1" cscript("msg1", strshow)
End If Else bAlertCookie.Value = 1 cscript("msg2", str2show) txtmemberNo.Text = "" End If Catch ex As Exception
Finally conn.Close() End Try Else bAlertCookie.Value = "1" cscript("msg", "input id is NO") txtmemberNo.Text = "" End If Else bAlertCookie.Value = "1" cscript("msg", "textbox emtpty") txtmemberNo.Text = "" End If End Sub 大多数人的代码到这里就完了,可是没有处理页面缓存问题,我们这里用Cookies处理,代码如下: Public Sub cscript(ByVal key As String, ByVal meg As String) Dim scriptFunction As New StringBuilder scriptFunction.Append("<script language= javascript>") scriptFunction.Append("function getCookie (sCookieName)" & Chr(13) & Chr(10)) scriptFunction.Append("{" & Chr(13) & Chr(10)) scriptFunction.Append("var sName=sCookieName+""="", ichSt, ichEnd;" & Chr(13) & Chr(10)) scriptFunction.Append("var sCookie=document.cookie;" & Chr(13) & Chr(10)) scriptFunction.Append("if ( sCookie.length && ( -1 != (ichSt = sCookie.indexOf(sName)) ) )" & Chr(13) & Chr(10)) scriptFunction.Append("{" & Chr(13) & Chr(10)) scriptFunction.Append("if (-1 == ( ichEnd = sCookie.indexOf("";"",ichSt+sName.length) ) )" & Chr(13) & Chr(10)) scriptFunction.Append("ichEnd = sCookie.length;" & Chr(13) & Chr(10)) scriptFunction.Append("return unescape(sCookie.substring(ichSt+sName.length,ichEnd));" & Chr(13) & Chr(10)) scriptFunction.Append("}" & Chr(13) & Chr(10))
scriptFunction.Append("return null;" & Chr(13) & Chr(10)) scriptFunction.Append("}" & Chr(13) & Chr(10))
scriptFunction.Append("if(getCookie(""bAlert"")=='1')" & Chr(13) & Chr(10)) scriptFunction.Append("{alert(""" & meg & """);}" & Chr(13) & Chr(10)) scriptFunction.Append("</script>") RegisterStartupScript(key, scriptFunction.ToString()) End Sub
哈哈,怎么样,是不是不太一样啊。 
2005年1月5日16:07:24 
|