可以转到mainmenu.aspx吗?可以的话,用这段代替mainmenu.aspx的page_load:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 Label2.Text = Session("chkuser") Response.Write(">>>") Response.Write(Session("chkuser")) Response.Write("<<<") Label4.Text = Today End Sub试试
session这样用并没有错,但是我觉得楼主这样用来判断用户存不存在不是太好,一般都是Select * from [user] where id=.. pwd=... ,然后返回的dt.判断count是否为1,最好pwd要经过md5加密.
VB.NET快忘记了...但你的登陆判断显得累赘了...为何还要用一人inta来记录是否合格呢? stra = Trim(TextBox1.Text) strb = Trim(TextBox2.Text) IF dr.Read Then If stra = dr("user_id") And strb = dr("password") Then Session("chkuser") = Trim(TextBox1.Text) Response.Redirect("../mainmenu.aspx") Else Response.Write("<script>alert('对不起,用户名或密码错误,请重新输入!')</script>") End If End If
up一下!
页面上加上<%@ Page EnableSessionState="True"
或者webconfig里面
< sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
我用C#写的时候,都是要这样:NameTxt.Text=Session["Name"].ToString();
'在此处放置初始化页的用户代码
Label2.Text = Session("chkuser")
Response.Write(">>>")
Response.Write(Session("chkuser"))
Response.Write("<<<")
Label4.Text = Today
End Sub试试
stra = Trim(TextBox1.Text)
strb = Trim(TextBox2.Text)
IF dr.Read Then
If stra = dr("user_id") And strb = dr("password") Then
Session("chkuser") = Trim(TextBox1.Text)
Response.Redirect("../mainmenu.aspx")
Else
Response.Write("<script>alert('对不起,用户名或密码错误,请重新输入!')</script>")
End If
End If
session是Object类型的,所以要ToString()吧.
—————————————————————
不需要的;vb中定义一个变量是可以不申请类型的。
—————————————————————
不需要的;vb中定义一个变量是可以不申明类型的。