日期:2014-05-18  浏览次数:20384 次

如何判断已经登陆 asp.net 急
登陆时候
strCon   =   ConfigurationSettings.AppSettings( "strCon ")  
conn   =   new   sqlconnection(strCon)
strSql= "select   *   from   users   where   user_name= ' "   &   txtName.text   &   " '   and   user_password= ' "   &   txtPwd.text   &   " 'and   user_roles=1 "
                Dim   cmd   As   New   SqlCommand(strSql,   conn)
                conn.open()
Dim   dr   As   SqlDatareader   =   cmd.executereader()
if   dr.read()   =   true   then
conn.close()
formsauthentication.setauthcookie(txtName.text,true)
response.redirect( "fnc\mandtview.aspx ")
Session( "user_name ")   =   txtName.text
                Session( "user_roles ")   =   1
else
conn.close()
message.text= "您输入的用户名密码不正确 "
end   if
进入其它页用      
Sub   page_load(ByVal   sender   As   Object,   ByVal   e   As   EventArgs)  
if   session( "user_name ")=0   then
response.redirect( "..\man_right.aspx ")
elseif   session( "user_roles ")=1   then
message.text=session( "user_name ")   & "   您好! "
end   if

        End   Sub
我这么写为什么不行?总是回到..\man_right.aspx了   好像session( "user_name ")=0这根我在

        Sub   Session_Start(ByVal   sender   As   Object,   ByVal   e   As   EventArgs)
                '   在会话启动时激发
                Session( "user_name ")   =   0
                Session( "user_roles ")   =   0
        End   Sub
声明这两个变量有关系么?谢谢大家乐啊

------解决方案--------------------
Session_Start事件里不要写代码
------解决方案--------------------
首先说下我对VB不怎么熟悉,我在这说说我大概的看法
Session( "user_name ") = txtName.text中txtName.text是字符串,
if session( "user_name ")=0,这个比较按照C#里应该是if session( "user_name ")== "0 "才会比较得出来吧?
比较是==,=是赋值?
------解决方案--------------------
判断Context.Request.IsAuthenticated确定是否登陆成功,如果成功,则是你Session的问题。Session( "user_name ") 不必预先声明,Session( "user_name ") = txtName.text就声明了一个session变量,key=user_name