以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 某个页面不需要验证用户身份,怎么办? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97592) |
||||||||
-- 作者:zhangjian222200 -- 发布时间:2017/3/15 11:44:00 -- 某个页面不需要验证用户身份,怎么办? 移动帮助文档,设计首页和登录页面,每个页面都验证是否通过了身份验证 假设某个页面不需要验证用户身份,怎么办?
|
||||||||
-- 作者:狐狸爸爸 -- 发布时间:2017/3/15 12:05:00 -- if e.Path = "无需验证的页面" then else \'验证用户身份 end if \'生成网页
|
||||||||
-- 作者:zhangjian222200 -- 发布时间:2017/3/19 9:49:00 -- 打开http://127.0.0.1/login.htm页面时,下述验证代码执行有问题,只执行msgbox(0)、1、2、8,3、4、5、6、7没有执行 现在将httprequest事件代码与login.htm内部函数代码贴出来 httprequest事件代码如下: Dim fl As String = "e:\\web\\" & e.path If filesys.FileExists(fl) Dim idx As Integer = fl.LastIndexOf(".") Dim ext As String = fl.SubString(idx) Select Case ext Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar" e.WriteFile(fl) Return \'这里必须返回 End Select End If msgbox(0) If e.Path = "index.htm" OrElse e.Path = "details.htm" OrElse e.Path = "getback.htm" OrElse e.Path = "register.htm" OrElse e.Path = "protocol.htm" OrElse e.Path = "zhucwc.htm" OrElse e.Path = "fillout.htm" OrElse e.Path = "quyu.htm" OrElse e.Path = "images.htm" OrElse e.Path = "success.htm" OrElse e.Path = "valid_register.htm" OrElse e.Path = "valid_fillout.htm" OrElse e.Path = "valid_quyu.htm" OrElse e.Path = "valid_images.htm" OrElse e.Path = "quyu_get.htm" Then Select Case e.Path Case "index.htm" \'首页 Functions.Execute("index",e) Case "details.htm" \'详情页面 Functions.Execute("details",e) Case "getback.htm" \'找回密码页面 Functions.Execute("getback",e) Case "register.htm" \'注册第1页,手机注册 Functions.Execute("register",e) Case "protocol.htm" \'注册第2页,服务协议 Functions.Execute("protocol",e) Case "zhucwc.htm" \'注册第3页,注册完成,提示页面 Functions.Execute("zhucwc",e) Case "fillout.htm" \'注册第4页,完善资料 Functions.Execute("fillout",e) Case "quyu.htm" \'注册第5页,区域资料 Functions.Execute("quyu",e) Case "images.htm" \'注册第6页,上传照片 Functions.Execute("images",e) Case "success.htm" \'注册第7页,资料填写完成,提示页面 Functions.Execute("success",e) Case "valid_register.htm" \'验证页面(register) Functions.Execute("valid_register",e) Case "valid_fillout.htm" \'验证页面(fillout) Functions.Execute("valid_fillout",e) Case "valid_quyu.htm" \'验证页面(quyu) Functions.Execute("valid_quyu",e) Case "valid_images.htm" \'验证页面(images) Functions.Execute("valid_images",e) Case "quyu_get.htm" \'注册第3页,完善资料(填入所在/家乡省|市|区县) Functions.Execute("quyu_get",e) End Select Else Dim wb As New weui \'1.加密解密 2.cookies释放 msgbox(1) \'身份验证 Dim Verified As Boolean \'用于标记用户是否通过了身份验证 Dim UserName As String = e.Cookies("isj") \'从cookie中获取用户名 Dim Password As String = e.Cookies("imm") \'从cookie中获取用户密码 msgbox(2) If e.Path = "login.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码 msgbox(3) If e.PostValues.ContainsKey("isj") AndAlso e.PostValues.ContainsKey("imm") Then msgbox(4) UserName = e.PostValues("isj") Password = e.PostValues("imm") End If End If If e.Cookies.ContainsKey("isj") AndAlso e.Cookies.ContainsKey("imm") Then msgbox(5) Dim dr As DataRow = DataTables("会员资料").Find("手机号 = \'" & UserName & "\'") If dr IsNot Nothing AndAlso dr("密码") = Password Then msgbox(6) Verified = True End If End If If Verified AndAlso e.Path = "login.htm" Then \'如果用户访问的是登录页,且身份验证成功 msgbox(7) wb.AppendCookie("isj",UserName) \'将用户名和密码写入cookie wb.AppendCookie("imm",Password) wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页 e.WriteString(wb.Build) \'生成网页 Return \'必须的 ElseIf Verified = False AndAlso e.Path <> "login.htm" Then \'如果用户身份验证失败,且访问的不是登录页面 msgbox(8) wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面 e.WriteString(wb.Build) \'生成网页 Return \'必须的 End If Select Case e.Path Case "login.htm" \'登录页面 Functions.Execute("login",e) Case "personal.htm" \'个人中心 Functions.Execute("personal",e) Case "myservice.htm" \'我的服务 Functions.Execute("myservice",e) End Select End If login.htm内部函数代码: Dim e As RequestEventArgs = args(0) Select Case e.Path Case "login.htm" Dim wb As New weui \'登录页面 wb.AddForm("","form1","login.htm") With wb.AddInputGroup("form1","ipg1","登录") If e.PostValues.ContainsKey("isj") AndAlso e.PostValues.ContainsKey("imm") Then \'判断是否是验证失败后的重新登录 wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示. End If With .AddInputCell("ic1") \'通过InputCell增加输入框(1表示突出显示,2表示红色警示图标) .AddLabel("lsj","手机",0) \'增加标签(0显示在左边) .AddInput("isj","text",1).PlaceHolder= "请输入手机号" \'增加输入框(0靠左显示,1居中显示,2靠右显示) End With With .AddInputCell("ic2") .AddLabel("lmm","密码",0) .AddInput("imm","password",1).PlaceHolder= "请输入密码" End With With .AddInputCell("ic3") .AddLabel("lyz","验证码",0) .AddInput("iyz","number",1).PlaceHolder= "请输入验证码" .AddVcodeButton("vyz","获取验证码",2) \'0靠左显示,1居中显示,2靠右显示 End With .AddSwitch("jizhumima","记住密码") With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "登录", "","submit") \'"/index.htm") End With With wb.AddButtonGroup("form1","btg2", False) .Add("btn2", "免费注册","","/register.htm").Kind = 1 .Add("btn3", "忘记密码","","/getback.htm").Kind = 1 End With End With e.WriteString(wb.Build) \'生成网页 End Select [此贴子已经被作者于2017/3/19 11:17:03编辑过]
|
||||||||
-- 作者:狐狸爸爸 -- 发布时间:2017/3/20 8:40:00 -- 这中执行逻辑问题,应该自己去处理分析,代码不执行,原因很简单,前面的if条件不符合。 msgbox(3)要执行,e.path必须等于“login.htm”
|
||||||||
-- 作者:zhangjian222200 -- 发布时间:2017/3/20 18:08:00 -- 找了好久,问题还在,问题在3楼,这里上传例子,只执行msgbox(0)、1、2、8,3有时候执行,有时候不执行,4、5、6、7不执行 这是项目文件:
这是web文件夹:
[此贴子已经被作者于2017/3/20 18:11:05编辑过]
|
||||||||
-- 作者:有点色 -- 发布时间:2017/3/20 19:18:00 -- 这段
If e.Cookies.ContainsKey("isj") = False OrElse e.Cookies.ContainsKey("imm") = False Then msgbox(5)
Dim dr As DataRow = DataTables("会员资料").Find("手机号 = \'" & UserName & "\'")
If dr IsNot Nothing AndAlso dr("密码") = Password Then
msgbox(6)
Verified = True
End If
End If
|
||||||||
-- 作者:zhangjian222200 -- 发布时间:2017/3/20 21:25:00 -- 浏览器输入http://127.0.0.1/index.htm,弹出3遍0、1、2、5、8,才进入index.htm页面,问题是我已经把index.htm,放在if语句前端,应该是不需要验证的,怎么还是执行else后面的1、2、5、8,为什么?index. htm没有msgbox [此贴子已经被作者于2017/3/20 21:27:07编辑过]
|
||||||||
-- 作者:有点蓝 -- 发布时间:2017/3/20 22:06:00 -- 把msgbox(0) 改为 msgbox("0===" & e.Path & ",fl=" & fl) 就能看出问题在哪了 代码调试不仅仅是会使用msgbox,还要会使用msgbox显示一些关键信息
|
||||||||
-- 作者:有点蓝 -- 发布时间:2017/3/20 22:17:00 -- web服务调试建议使用日志,弹出那么多的提示框不知道你烦不烦 |