Network Analyst routing
ArcGIS_Routing_VBNet\App_Code\CustomMapHandler.vb
' Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Web

Namespace MyHandler
  Public Class CustomMapHandler
    Inherits ESRI.ArcGIS.ADF.Web.UI.WebControls.MapHandler
    Private serverObjectStateModifier As ServerObjectStateModifier = Nothing
    Private m_resource As ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItem = Nothing

    Public Sub New()
      MyBase.New()
      serverObjectStateModifier = New ServerObjectStateModifier()
    End Sub

    Protected Overrides Sub OnResourceInit(ByVal resource As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem)
      MyBase.OnResourceInit(resource)

      If resource.Name = "MapResourceItem0" Then
        CustomResourceInit(resource)
      End If
    End Sub

    Protected Sub CustomResourceInit(ByVal resource As ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItem)
      Dim modifiedNAContextApplied As Object = System.Web.HttpContext.Current.Session("ModifiedNAContextApplied")
      If modifiedNAContextApplied Is Nothing OrElse (Not CBool(modifiedNAContextApplied)) Then
        m_resource = resource

        serverObjectStateModifier.ApplySessionNAContext(resource)
        System.Web.HttpContext.Current.Session("ModifiedNAContextApplied") = True
      End If
    End Sub

    Protected Overrides Sub OnResourcesDispose(ByVal resourceManager As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager)
      MyBase.OnResourcesDispose(resourceManager)

      If CBool(System.Web.HttpContext.Current.Session("ModifiedNAContextApplied")) Then
        If Not m_resource Is Nothing Then
          serverObjectStateModifier.ApplyOriginalNAContext(m_resource)
          System.Web.HttpContext.Current.Session("ModifiedNAContextApplied") = False
          m_resource = Nothing
        End If
      End If
    End Sub
  End Class
End Namespace