in FMLab/Odata4ConsoleApplication/BrowserForm.cs [54:120]
private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
try
{
// Check if we are about to submit the SAML token returned by ACS.
if (String.Compare(e.Url.AbsoluteUri, GetUrl(), true) == 0)
{
// Extract ACS response.
if (this.Browser.Document != null && this.Browser.Document.All["wresult"] != null)
{
// Cancel the request so that the POST doesn't actually happen.
e.Cancel = true;
try
{
String acsResponse;
//
// The ACS response that needs to be posted back has to be in a very
// specific format.
//
dynamic wa = this.Browser.Document.All["wa"].DomElement;
String waString = System.Web.HttpUtility.HtmlDecode(wa.value);
#if false
Console.WriteLine("wa={0}", waString);
#endif
dynamic wresult = this.Browser.Document.All["wresult"].DomElement;
String wresultString = System.Web.HttpUtility.HtmlDecode(wresult.value);
wresultString = wresultString.Replace("&", "&");
#if false
Console.WriteLine("wresult={0}", wresultString);
#endif
dynamic wctx = this.Browser.Document.All["wctx"].DomElement;
String wctxString = System.Web.HttpUtility.HtmlDecode(wctx.value);
#if false
Console.WriteLine("wctx={0}", wctxString);
#endif
acsResponse = "wa=" + System.Web.HttpUtility.UrlEncode(waString, Encoding.ASCII) + "&" +
"wresult=" + System.Web.HttpUtility.UrlEncode(wresultString, Encoding.ASCII) + "&" +
"wctx=" + System.Web.HttpUtility.UrlEncode(wctxString, Encoding.ASCII);
#if false
Console.WriteLine("URL encoded ACS response:");
Console.WriteLine(acsResponse);
#endif
ReturnAcsResponse(acsResponse);
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
// Close the browser form.
this.Dispose();
}
}
}
catch (Exception )
{
}
}