Common Security PassThrough
Common_SecurityPassThrough_CSharp\SecurityPassThrough_Forms_CSharp\Default.aspx.cs
// 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.
// 

public partial class _Default : 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 void Page_PreInit(object sender, System.EventArgs e)
    {        

        if (!Page.IsPostBack)
        {
            // Get the identity from session.  This was initialized by the 
            // Login.aspx code-behind page
            string userIdentity = (string)Session["userIdentity"];

            // Set the identity for the map service.  This could also be done here
            // for multiple resources and/or for other resource types
            ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem 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)
            {
                // 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;
            }

            // Clear out the identity since we don't need it anymore
            Session["userIdentity"] = null;
        }
    }

}