HttpRequest事件
Functions.Execute("LogText", "e.Path =" & e.Path & ",e.Host =" & e.Host & ",e.Port = " & e.Port & ", 完整地址 = " & e.Request.URL.ToString)
Dim cmd As New SQLCommand
cmd.C
Dim wb As New weui
PopMessage("e.Path:" & e.Path)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim Verified As Boolean '用于标记用户是否通过了身份验证
Dim useid As Integer
Dim UserName As String = e.Cookies("name") '从cookie中获取用户名
Dim Password As String = e.Cookies("Pwd") '从cookie中获取用户密码
If e.Path = "logon.htm" OrElse e.path = "" Then'如果是通过登录页面访问,从PostValues即可中提取用户名和密码
PopMessage("e.Path:" & e.Path & "||" & e.PostValues.ContainsKey("name") & ">>" & e.PostValues.ContainsKey("Pwd"))
If e.PostValues.ContainsKey("name") AndAlso e.PostValues.ContainsKey("Pwd") Then
UserName = e.PostValues("name")
Password = Functions.Execute("加密", e.PostValues("Pwd"))
End If
End If
PopMessage("password:" & password)
If Password > "" Then
cmd.CommandText = "sel ect * from {DUse} where [Fid] = 1 and [UseName] = '" & UserName & "' and [Pwd] = '" & Password & "'"
Dim sdt As DataTable = cmd.ExecuteReader
PopMessage("sdt.DataRows.Count:" & sdt.DataRows.Count)
If sdt.DataRows.Count > 0 Then
useid = sdt.DataRows(0)("Itid")
Verified = True
Else
Verified = False
End If
Else
Verified = False
End If
If Verified AndAlso e.Path = "logon.htm" Then '如果用户访问的是登录页,且身份验证成功
PopMessage("T")
wb.AppendCookie("name", UserName) '将用户名和密码写入cookie
wb.AppendCookie("Pwd", Password)
wb.AppendCookie("useid", useid)
wb.InsertHTML("<meta http-equiv='Refresh' c>") '直接跳转到首页
e.WriteString(wb.Build) '生成网页
Return '必须的
ElseIf Verified = False AndAlso e.Path <> "logon.htm" Then '如果用户身份验证失败,且访问的不是登录页面
PopMessage("F")
wb.InsertHTML("<meta http-equiv='Refresh' c>") '那么直接跳转到登录页面
e.WriteString(wb.Build) '生成网页
Return '必须的
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Select Case e.Path
Case "logon.htm", ""
wb.AddPageTitle("", "pageheader", "云狐管理", "云狐管理有限公司")
wb.AddForm("", "Form1", "logon.htm")
With wb.AddInputGroup("Form1", "ipg1")
.AddInput("name", "用户名", "text")
.AddInput("pwd", "密码", "password")
End With
With wb.AddButtonGroup("Form1", "btg1", True)
.Add("btn1", "登录", "submit")
End With
e.WriteString(wb.Build)
End if
LOGTEXT 函数如下
Dim v = Args(0)
'PopMessage(v)
Dim msg As String
If Typeof v Is Exception Then '如果是Exception的异常类型,则递归获取所有的异常堆栈
Do While v IsNot Nothing
msg &= v.Message & vbcrlf & v.StackTrace & vbcrlf
v = v.InnerException
Loop
Else '其它情况只能传入错误的文本内容
msg = v
End If
Output.Logs("AppLogging").Add(Format( Date.Now,"yyyy-MM-dd HH:mm:ss.ffff") & vbCrLf & msg)
Output.Logs("AppLogging").Save(ProjectPath & "Mmsglog.txt",True) '日志位于当前项目目录里
Output.Logs("AppLogging").Clear
LOGTEXT 得到的结果如下
2022-08-30 14:53:14.1918
e.Path =logon.htm,e.Host =ntowaaan.free.idcfengye.com,e.Port = 8010, 完整地址 = http://ntowaaan.free.idcfengye.com:8010/logon.htm
2022-08-30 14:53:18.9828
由于线程退出或应用程序请求,已中止 I/O 操作。
在 System.Net.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 size)
在 System.IO.BufferedStream.ReadByte()
在 Foxtable.RequestEventArgs.o00.__O_O_.(Stream A_0)
在 Foxtable.RequestEventArgs.O.0O_oO.()
2022-08-30 14:53:18.9898
e.Path =logon.htm,e.Host =ntown.free.idcfengye.com,e.Port = 8010, 完整地址 = http://ntown.free.idcfengye.com:8010/logon.htm