Welcome to MSDN Blogs Sign in | Join | Help

HealthVault FAQ

This blog hosts FAQ questions (and answers) for developers using the HealthVault SDK

Syndication

Handling HealthServiceCredentialTokenExpiredException in .NET SDK

Applications are expected to Handle the HealthServiceCredentialTokenExpiredException. The best way to handle this error is to Redirect the user to sign-on again, the best place to implement it in your basepage’s page error handler. Here is some sample code which accomplishes the same, please note this code should be in our basepage or any page deriving from HealthServicePage :

/// <summary>
/// This error block handles the case of an expired user token. User
/// tokens expire after 24 hours or time set by persistent tokens
/// for the "keep me sign-in" feature. These tokens and are stored in the cookie,
/// which has no default timeout. Developers are encouraged to expire cookies 
/// sooner, but this code handles the case where the cookie does not
/// expire and the browser window is left open for over 24 hours.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Error(object sender, EventArgs e)
{
    Exception ex = Server.GetLastError();

    if (ex is HealthServiceCredentialTokenExpiredException)
    {
        WebApplicationUtilities.RedirectToLogOn(HttpContext.Current);
    }

    ShowError(ex);
}
Your page will need to implement ShowError method or you comment it and re-throw the un-caught exceptions.

Published Friday, November 06, 2009 12:15 PM by vaibhavb

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
Page view tracker