以下代码放到httprequest中,考虑5楼的效率问题,将3楼代码做了7处改动,具体见下面粉色字体,还请帮看看,谢谢!
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
Dim wb As New weui '(1.删除此行,是否可以? 好像这里不需要框架)
Dim Verified As Boolean = False '用于标记用户是否通过了身份验证(2.考虑到每次访问页面,都执行此行代码,每次都重新定义且赋值为空,把这个变量定义到全局变量,当Verified为false时,执行下面的代码)
If Verified = False Then
Dim UserName As String = e.Cookies("username") '从cookie中获取用户名 (3.我感觉这里不需要赋值,因为都是登录后Verified为true,才赋值)
Dim Password As String = e.Cookies("password") '从cookie中获取用户密码(4.我感觉这里不需要赋值,因为都是登录后Verified为true,才赋值)
If e.Path = "login.htm" '如果是通过登录页面访问,从PostValues即可中提取用户名和密码(5.我的登录页面是login.htm,改为login.htm)
If e.PostValues.ContainsKey("username") AndAlso e.PostValues.ContainsKey("password") Then
UserName = e.PostValues("username")
Password = e.PostValues("password")
End If
End If
Dim dr As DataRow = DataTables("密码表").Find("用户名 = '" & username & "'")
If dr IsNot Nothing AndAlso dr("密码") = password Then
Verified = True
End If
If Verified AndAlso e.Path = "login.htm" Then '如果用户访问的是登录页,且身份验证成功
wb.AppendCookie("username",UserName) '将用户名和密码写入cookie
wb.AppendCookie("password",Password)
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页(6.我的主页是127.0.0.1/index.htm,请教此行怎么写?)
e.WriteString(wb.Build) '生成网页
Return '必须的
ElseIf Verified = False AndAlso e.Path <> "login.htm" Then '如果用户身份验证失败,且访问的不是登录页面
wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面(7.我的登录页是127.0.0.1/login.htm,请教此行怎么写?)
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
End If
Select Case e.Path
Case "index.htm" '首页
Functions.Execute("index",e)
Case "details.htm" '详情页面
Functions.Execute("details",e)
Case "login.htm" '登录页面
Functions.Execute("login",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 "fillout.htm" '注册第3页,完善资料
Functions.Execute("fillout",e)
Case "images.htm" '注册第4页,上传照片
Functions.Execute("images",e)
Case "success.htm" '注册第5页,注册成功
Functions.Execute("success",e)
Case "personal.htm" '个人中心
Functions.Execute("personal",e)
End Select
[此贴子已经被作者于2017/3/9 20:36:17编辑过]