webdiskbasepage.vb

来自「是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义」· VB 代码 · 共 80 行

VB
80
字号
Imports Microsoft.VisualBasic
Imports System.data
Imports System.io
Public Class WebDiskBasePage
    Inherits System.Web.UI.Page

    Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
        '写入错误信息到XML文件
        Dim exc As Exception = Server.GetLastError
        If Not IsNothing(Session("User")) Then
            clsDebug.DebugFileOut(exc, HttpContext.Current.Request.Url.ToString)
        End If
        Server.ClearError()
        Server.Transfer("../Help/Message_Err.aspx?Error=" + Server.HtmlEncode(exc.Message))
    End Sub

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsNothing(Session("User")) Or _
                IsNothing(Session("User")) Or _
                IsNothing(Session("UserDir")) Or _
                IsNothing(Session("ServerDir")) Then
            GC.Collect() '强制垃圾回收
            '用户和日志缓存已无效,需重新加载
            Response.Redirect("/WebDisk/login.aspx", True)
        End If
        If Not Me.IsPostBack Then
            '限定不能访问xml文件夹
            PageVisitLimit()
        End If
    End Sub

    '根据登录用户自动设置页面能否访问
    Protected Sub PageVisitLimit()
        Dim LoginType As Data.LoginType
        LoginType = Session("LoginType")
        If Data.LoginType.NORMALUSER Then
            Dim strDir As String = HttpContext.Current.Request.FilePath
            Dim Index As Integer = strDir.LastIndexOf("/")
            strDir = strDir.Substring(0, Index) '获取目录,即整个目录下的页面都不能访问
            Index = strDir.LastIndexOf("/")
            strDir = strDir.Substring(Index + 1).ToLower
            Dim strPageName As String = HttpContext.Current.Request.FilePath
            Index = strPageName.LastIndexOf("/")
            strPageName = strPageName.Substring(Index + 1).ToLower '配置目录,日志目录都不能访问
            If strDir = "xml" Or _
                 strPageName = "superadmin.aspx" Then

                ' Response.Redirect("../Help/Error.aspx")
                'Response.Redirect("../default.aspx")
                Server.Transfer("/WebDisk/Help/Alert.htm")
            End If
            '普通用户只能访问网络硬盘服务
        End If
    End Sub

    '向ErrorLog.XML文件写入页面错误信息
    Protected Sub AddErrorLogToXML(ByVal Name As String, ByVal Msg As String)
        Dim ds As New DataSet
        Dim dt As DataTable
        If Not File.Exists(Server.MapPath(Data.C_ErrorLogXmlMapPath)) Then
            '"~/XML/LoginLog.xml"文件不存在则建立该文件
            dt = ds.Tables.Add(0)
            dt.Columns.Add("Name")
            dt.Columns.Add("Date")
            dt.Columns.Add("msg")
            '建立一行临时数据
            Dim Value() As String = {Name, Now.ToString, Msg}
            dt.Rows.Add(Value)
            ds.WriteXml(Server.MapPath(Data.C_ErrorLogXmlMapPath))
        Else
            ds.ReadXml(Server.MapPath(Data.C_ErrorLogXmlMapPath))
            dt = ds.Tables(0)
            Dim Value() As String = {Name, Now.ToString, Msg}
            dt.Rows.Add(Value)
            ds.WriteXml(Server.MapPath(Data.C_ErrorLogXmlMapPath))
        End If
        ds = Nothing
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?