/// <summary>
        /// Obtains the next reader service during the discovery process
        /// being managed by a session variable tracking cirlce of trusts
        /// currently being checked.
        /// </summary>
        /// <param name="serviceProviderUtility">ServiceProviderUtility containing circle-of-trust information.</param>
        /// <param name="context">HttpContext containing session, request, and response objects.</param>
        /// <returns>
        /// Returns the URL found in the currently checked circle-of-trust file if specified, null otherwise.
        /// </returns>
        public static Uri GetReaderServiceUrl(ServiceProviderUtility serviceProviderUtility, HttpContextBase context)
        {
            HttpSessionStateBase session = context.Session;
            Uri readerSvcUrl = null;

            var cotList = (ArrayList) session[CommonDomainDiscoverySessionAttribute];
            if (cotList == null)
            {
                // Obtain the list of currently tracked circle-of-trusts with
                // reader service if not already known.
                cotList = new ArrayList();
                foreach (string cotName in serviceProviderUtility.CircleOfTrusts.Keys)
                {
                    var cot = serviceProviderUtility.CircleOfTrusts[cotName];
                    if (cot.ReaderServiceUrl != null)
                    {
                        cotList.Add(cotName);
                    }
                }
            }

            IEnumerator enumerator = cotList.GetEnumerator();
            if (enumerator.MoveNext())
            {
                // Try the first service in the list
                var cotName = (string) enumerator.Current;
                cotList.Remove(cotName);
                session[CommonDomainDiscoverySessionAttribute] = cotList;
                var cot = serviceProviderUtility.CircleOfTrusts[cotName];
                readerSvcUrl = new Uri(cot.ReaderServiceUrl.AbsoluteUri);
            }

            return readerSvcUrl;
        }
        public void ProcessRequest(HttpContext Context)
        {
            HttpRequest Request = Context.Request;
            HttpResponse Response = Context.Response;
            HttpSessionState Session = Context.Session;
            Cache Cache = Context.Cache;

            if (Request.Url.AbsoluteUri.EndsWith("acs.saml2"))
            {
                string errorMessage = null;
                string errorTrace = null;
                AuthnResponse authnResponse = null;
                ServiceProviderUtility serviceProviderUtility = null;

                try
                {
                    serviceProviderUtility = (ServiceProviderUtility)Cache["spu"];
                    if (serviceProviderUtility == null)
                    {
                        serviceProviderUtility = new ServiceProviderUtility(Context);
                        Cache["spu"] = serviceProviderUtility;
                    }

                    authnResponse = serviceProviderUtility.GetAuthnResponse(Context);
                }
                catch (Saml2Exception se)
                {
                    errorMessage = se.Message;
                    errorTrace = se.StackTrace;
                    if (se.InnerException != null)
                        errorTrace += "<br/>" + se.InnerException.StackTrace;
                }
                catch (ServiceProviderUtilityException spue)
                {
                    errorMessage = spue.Message;
                    errorTrace = spue.StackTrace;
                    if (spue.InnerException != null)
                        errorTrace += "<br/>" + spue.InnerException.StackTrace;
                }

                String userName = null;
                if (authnResponse != null)
                {
                    FedletUser User = new FedletUser();
                    User.UserName = authnResponse.SubjectNameId;

                    userName = authnResponse.SubjectNameId;
                    foreach (string AttributeName in authnResponse.Attributes.Keys)
                    {
                        ArrayList AttributeValues = authnResponse.Attributes[AttributeName] as ArrayList;
                        string AttributeValue = "";
                        if (AttributeValues.Count > 0)
                        {
                            AttributeValue = AttributeValues[0] as String;
                        }

                        User.Attributes[AttributeName] = AttributeValue;

                    }

                    Session["FedletUser"] = User;

                    if (Request["RelayState"] != null)
                    {
                        Response.Redirect(Request["RelayState"]);
                    }
                    else
                    {
                        Response.Redirect(WebConfigurationManager.AppSettings["fedletController.defaultRelayState"]);
                    }
                }
                else
                {
                    userName = errorMessage;
                }

            }
            else
            {
                Response.StatusCode = 500;
                Response.StatusDescription = "Not a valid saml2 action";
            }
        }