CardSpace errors. CardSpace has a lot of potential errors, 31 at the current count, but how to you catch them on the client? The CardSpace samples don't illustrate this, and end up submitting a null token to the relying party. This isn't particularly friendly to the user, or to the relaying party; ideally you'd be able to detect that a user canceled the CardSpace dialog and not submit your form.

If you examine the error list you will see there is a specific HRESULT, IDS_E_ICARD_USERCANCELLED which is returned when the user cancels the CardSpace UI, but the question remains how do you access the return result? The Microsoft CardSpace UI (and Perpetual Motion's CardSpace plugin for Firefox) return the HRESULT as a JavaScript exception that you can trap. For example

<object type="application/x-informationCard" id="_xmltoken">
  <param name="requiredClaims"
    value="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"/>
</object>
<input type="hidden" name="xmltoken">
<script language="javascript">
  function getToken()
  {
   var xmltkn=document.getElementById("_xmltoken");
    try
    {
        var token=document.getElementById("_xmltoken");
        var tokenField= document.getElementById("xmltoken");
        tokenField.value = xmltkn.value;
    }
    catch (ex)
    {
       alert("An unspecified error occurred! " + ex.number);
    }
}
</script>
<button onclick="getToken()">Test</button>

So you can see ex.number will contain the error HRESULT, which you can check and act on accordingly.

 

Technorati tags: