以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 自定义函数的问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=144114) |
-- 作者:dengk03 -- 发布时间:2019/12/11 10:53:00 -- 自定义函数的问题 为啥我按照说明把登录页面的代码放到自定义函数里,调试的时候页面就不显示了?放到网络监视器里能正常运行? Case "logon.htm" \'登录页面 Functions.Execute("logon",e) 自定义函数 Dim e As RequestEventArgs = args(0) Dim wb As New WeUI wb.AddPageTitle("","pageheader","管理","管理app") wb.AddPageFooter("","pf1","Copyright & Copy; ") If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then \'判断是否是验证失败后的重新登录 wb.AddTopTips("","toptip1","用户名或密码错误!").msec = 2000 \'如果用户通过登录按钮访问,则给用户一个2秒的提示. End If wb.AddForm("","form1","logon.htm") With wb.AddInputGroup("form1","ipg1") .AddInput("username","户名","text") .AddInput("password","密码","password") End With With wb.AddButtonGroup("form1","btg1",True) .Add("btn1", "登录", "submit") End With |
-- 作者:2900819580 -- 发布时间:2019/12/11 11:01:00 -- e.WriteString(wb.Build) \'生成网页 |
-- 作者:有点蓝 -- 发布时间:2019/12/11 11:02:00 -- httprequest的完整代码放到txt发上来看看 |
-- 作者:dengk03 -- 发布时间:2019/12/11 11:27:00 -- 加上e.WriteString(wb.Build) \'生成网页 的确正常了,但是出现了新问题 发现用自定义函数以后我在登陆页面刷新,十次有5次刷不出来,其他页面也是 而全部代码放到网络监视器里,每次刷新都能成功。这是什么情况? 监视器里所有代码 Dim fl As String = ProjectPath & "web/" & e.path Dim path As String = "foxtableAppTest" 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",".txt" e.WriteFile(fl) Return \'这里必须返回 End Select End If Dim wb As New weui \'身份验证 Dim Verified As Boolean \'用于标记用户是否通过了身份验证 Dim UserName As String = e.Cookies("username") \'从cookie中获取用户名 Dim Password As String = e.Cookies("password") \'从cookie中获取用户密码 If e.Path = "logon.htm" \'如果是通过登录页面访问,从PostValues即可中提取用户名和密码 If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then UserName = e.PostValues("username") Password = e.PostValues("password") End If End If If UserName = "张三" AndAlso Password = "888" Then \'实际使用的时候,请改为从数据库读取用户名和密码进行比较 Verified = True ElseIf Username = "李四" AndAlso Password="999" Then Verified = True End If If Verified AndAlso e.Path = "logon.htm" Then \'如果用户访问的是登录页,且身份验证成功 wb.AppendCookie("username",UserName) \'将用户名和密码写入cookie wb.AppendCookie("password",Password) wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'直接跳转到首页 e.WriteString(wb.Build) \'生成网页 Return \'必须的 ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then \'如果用户身份验证失败,且访问的不是登录页面 wb.InsertHTML("<meta http-equiv=\'Refresh\' c>") \'那么直接跳转到登录页面 e.WriteString(wb.Build) \'生成网页 Return \'必须的 End If \'开始生成网页 Select Case e.path Case "logon.htm" \'登录页面 Functions.Execute("logon",e) Case "exit.htm" \'退出登录 Functions.Execute("exit",e) Case "", "default.htm" \'首页 Functions.Execute("default",e) End Select e.WriteString(wb.Build) \'生成网页 [此贴子已经被作者于2019/12/11 11:30:12编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/12/11 11:54:00 -- 4楼最后一句去掉 e.WriteString(wb.Build) 如果函数里面已经调用,外面就不能在调用,e.WriteString不能重复使用
|
-- 作者:goe12345 -- 发布时间:2019/12/12 11:06:00 -- 在登录页面中 在登录页面中,在function语句下面,加一条return语句 |