public void ProcessRequest(HttpContext context) { String response = String.Empty; bool redirect = false; IOpenUrlQuery ouQuery = OpenUrlQueryFactory.CreateOpenUrlQuery(HttpUtility.UrlDecode(context.Request.QueryString.ToString())); BHLOpenUrlProvider openurl = new BHLOpenUrlProvider(); openurl.UrlFormat = ConfigurationManager.AppSettings["CitationUrlFormat"]; openurl.ItemUrlFormat = ConfigurationManager.AppSettings["CitationItemUrlFormat"]; openurl.TitleUrlFormat = ConfigurationManager.AppSettings["CitationTitleUrlFormat"]; IOpenUrlResponse ouResponse = openurl.FindCitation(ouQuery); // Format the response as requested String format = context.Request.QueryString["format"] as String; if (format == null) { format = "redirect"; } switch (format) { case "xml": response = ouResponse.ToXml(); context.Response.ContentType = "text/xml"; break; case "json": response = ouResponse.ToJson(); context.Response.ContentType = "text/json"; break; case "html": response = this.FormatAsHTML(ouResponse); context.Response.ContentType = "text/html"; break; case "redirect": redirect = true; if (ouResponse.Status == ResponseStatus.Error || ouResponse.Status == ResponseStatus.Undefined) { // Set cookie to be read on the openurlhelp page HttpCookie cookie = new HttpCookie("OpenUrlMessage", ouResponse.Message); cookie.Expires = DateTime.Now.AddSeconds(10); context.Response.Cookies.Add(cookie); response = "/openurlhelp.aspx"; break; } else { switch (ouResponse.citations.Count) { case 0: response = "/openurlnone.aspx"; break; case 1: response = (ouResponse.citations[0].Url != String.Empty ? ouResponse.citations[0].Url : (ouResponse.citations[0].ItemUrl != String.Empty ? ouResponse.citations[0].ItemUrl : ouResponse.citations[0].TitleUrl)); break; default: string matches = string.Empty; string lastTitleUrl = string.Empty; int numCitations = 0; // Build a list of the identifiers foreach (OpenUrlResponseCitation citation in ouResponse.citations) { // If more than 50 citations, just show title-level information if (citation.Url.Length > 0 && ouResponse.citations.Count < 50) { matches += (matches.Length > 0) ? "|" : ""; matches += "p" + citation.Url.Substring(citation.Url.LastIndexOf("/") + 1); numCitations++; } else if (citation.ItemUrl.Length > 0 && ouResponse.citations.Count < 50) { matches += (matches.Length > 0) ? "|" : ""; matches += "i" + citation.ItemUrl.Substring(citation.ItemUrl.LastIndexOf("/") + 1); numCitations++; } else { if (citation.TitleUrl != lastTitleUrl) { matches += (matches.Length > 0) ? "|" : ""; matches += "t" + citation.TitleUrl.Substring(citation.TitleUrl.LastIndexOf("/") + 1); lastTitleUrl = citation.TitleUrl; numCitations++; } } } if (numCitations == 1 && lastTitleUrl != string.Empty) { response = lastTitleUrl; } else { response = "/openurlmultiple.aspx?id=" + matches; } break; } } break; } // Return the response (redirecting if necessary) if (redirect) { context.Response.Redirect(response); } else { context.Response.Write(response); } }