⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.asax

📁 asp.net技术内幕的书配源码
💻 ASAX
字号:
<%@ Import Namespace="System.Data" %>

<Script Runat="Server">

Sub Application_BeginRequest
  Dim dtblBadLinks As DataTable
  Dim strThisUrl As String
  Dim strSelect As String
  Dim arrMatches() As DataRow
  Dim strGoodLink As String

  dtblBadLinks = GetBadLinks()
  strThisUrl = Request.Path.ToLower()
  If Request.ApplicationPath <> "/" Then
    strThisUrl = strThisUrl.Remove( 0, Request.ApplicationPath.Length )
  End If
  strSelect = "badlink='" & strThisURL & "'"
  arrMatches = dtblBadLinks.Select( strSelect, "badlink" )
  If arrMatches.Length > 0 Then
    strGoodLink = arrMatches( 0 )( "goodlink" )
    strGoodLink = Request.ApplicationPath & strGoodLink
    Context.RewritePath( strGoodLink )
  End If
End Sub

Function GetBadLinks() As DataTable
  Dim dstBadLinks As DataSet
  Dim dtblBadLinks As DataTable

  dtblBadLinks = Context.Cache( "badlinks" )
  If dtblBadLinks Is Nothing Then
    dstBadLinks = New DataSet
    dstBadLinks.ReadXml( Server.MapPath( "badlinks.xml" ) )
    dtblBadLinks = dstBadLinks.Tables( 0 )
    Context.Cache.Insert( "badlinks", _
      dtblBadLinks, _
      New CacheDependency( Server.MapPath( "badlinks.xml" ) ) )
  End If
  Return dtblBadLinks
End Function

</Script>       

⌨️ 快捷键说明

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