Common Security PassThrough
Common_SecurityPassThrough_CSharp\SecurityPassThrough_Win_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 
{
    protected void Page_PreInit(object sender, System.EventArgs e)
    {
        // At startup, we check whether all resources can be initialized with the
        // current user's identity. We've already done impersonation in the
        // Global.asax, so the page is running with the browser user's identity. 
        // Note this code is optional, as it just displays a message if a service
        // can't be connected to.

        if (!Page.IsPostBack)
        {
            bool resourceFailed = false;

            // See whether we can initialize each resource. Since we're 
            // impersonating the user, initialization failure can mean an invalid 
            // user for the service.
            foreach (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem 
                mapResourceItem in MapResourceManager1.ResourceItems)
            {
                // If not already initialized, attempt to initialize the resource
                if (mapResourceItem.Resource == null ||
                    !mapResourceItem.Resource.Initialized)
                {
                    mapResourceItem.InitializeResource();
                }

                // Set failure flag if this resource fails to initialize
                if (mapResourceItem.FailedToInitialize)
                    resourceFailed = true;
            }

            // 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 = resourceFailed;
        }
    }
}