Common Security PassThrough
Common_SecurityPassThrough_VBNet\SecurityPassThrough_Forms_VBNet\Default.aspx.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
Partial Public Class _Default
  Inherits System.Web.UI.Page
  ' We set the resource's identity in PreInit because it has to be done before
  ' any of the ADF controls attempt to access the resource.
  Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
    If (Not Page.IsPostBack) Then
      ' Get the identity from session.  This was initialized by the 
      ' Login.aspx code-behind page
      Dim userIdentity As String = CStr(Session("userIdentity"))

      ' Set the identity for the map service.  This could also be done here
      ' for multiple resources and/or for other resource types
      Dim mapResourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = MapResourceManager1.ResourceItems.Find("MapResourceItem0")
      mapResourceItem.Definition.Identity = userIdentity

      ' Initialize the resource to check whether the identity is valid. This
      ' is not required, but can be used to trigger logic for when the user
      ' does not have the permissions to access the service.  Here, this is 
      ' used to display an informative message.
      mapResourceItem.InitializeResource()

      If mapResourceItem.FailedToInitialize Then
        ' If one or more resources couldn't be connected to, display the 
        ' label containing the notification message.  Note that failure 
        ' could also be caused by other issues, such as the map server or 
        ' service being unavailable.
        ResourceFailureLabel.Visible = True
      End If

      ' Clear out the identity since we don't need it anymore
      Session("userIdentity") = Nothing
    End If
  End Sub
End Class