HealthVault OfflinewebApplication gives HealthServiceException error: "The authentication token element of the request is required for this method."
<p>hi,
I am developing an OfflineWebApplication using HealthVault sdk in asp.net application.  My application creates the connection, but it does not get the personinfo and selectrecordid. It gives a HealthServiceException error: "The authentication token element of the request is required for this method." This error is given at mentioned line:</p>

<pre><code>Guid recordid = connection.GetPersonInfo().SelectedRecord.Id;
</code></pre>

<p>This is default.aspx.cs code page where create connection and get record of "Condition" from HealthVault user account and bind into grid. But it gives above error, so please give some help quickly.</p>

<pre><code>public partial class _Default: HealthServiceActionPage
{        
    protected void Page_Load(object sender, EventArgs e)
    {
       // Guid personID = new Guid("63a7f660-c7d1-4356-bf88-acc796a3f93a");
        Guid personid=new Guid("12255cce-6e9b-421b-a171-6a011b480011");                        
        OfflineWebApplicationConnection connection = HealthVaultConnectionManager.CreateConnection(new Guid(ConfigurationManager.AppSettings["ApplicationId"]),personid);

        Guid recordid = connection.GetPersonInfo().SelectedRecord.Id;
        HealthRecordAccessor accessor = new HealthRecordAccessor(connection,recordid);
        HealthRecordSearcher searcher = accessor.CreateSearcher();
        HealthRecordFilter filter = new HealthRecordFilter();
        filter.TypeIds.Add(Microsoft.Health.ItemTypes.Condition.TypeId);
        searcher.Filters.Add(filter);
        HealthRecordItemCollection conditioncollection = searcher.GetMatchingItems()[0];

        DataTable ConditionTable = new DataTable();

        DataColumn Name = new DataColumn("Name");
        DataColumn status = new DataColumn("Status");
        DataColumn onsetdate = new DataColumn("OnsetDate");
        DataColumn stopreson = new DataColumn("StopReason");
        DataColumn stopdate = new DataColumn("StopDate");

        Name.DataType = System.Type.GetType("System.String");
        status.DataType = System.Type.GetType("System.String");
        onsetdate.DataType = System.Type.GetType("System.DateTime");
        stopreson.DataType = System.Type.GetType("System.String");
        stopdate.DataType = System.Type.GetType("System.DateTime");

        ConditionTable.Columns.Add(Name);
        ConditionTable.Columns.Add(status);
        ConditionTable.Columns.Add(onsetdate);
        ConditionTable.Columns.Add(stopreson);
        ConditionTable.Columns.Add(stopdate);

        foreach (var items in conditioncollection)
        {                
            DataRow row = ConditionTable.NewRow();
            Microsoft.Health.ItemTypes.Condition condition = new Condition();
            row["Name"] = condition.Name.Text;
            row["status"]= condition.Status.Text;
            row["onsetdate"]=new DateTime(condition.OnsetDate.ApproximateDate.Year,condition.OnsetDate.ApproximateDate.Month.Value,condition.OnsetDate.ApproximateDate.Day.Value);
            row["stopreson"]=condition.StopReason;
            row["stopdate"] = new DateTime(condition.StopDate.ApproximateDate.Year, condition.StopDate.ApproximateDate.Month.Value, condition.StopDate.ApproximateDate.Day.Value);
            ConditionTable.Rows.Add(row);
        }
        grdcondition.DataSource = ConditionTable;
        grdcondition.DataBind();
        //Uri HealthServiceUrl = new Uri("https://platform.healthvault-ppe.com/platform/");
        //ApplicationInfo info = ApplicationConnection.GetApplicationInfo();
        //WebApplicationCredential cred = (WebApplicationCredential)this.PersonInfo.Connection.Credential;

        //String authToken = cred.SubCredential;

        //WebApplicationCredential newCred = new WebApplicationCredential(new Guid(ConfigurationManager.AppSettings["ApplicationId"]), authToken);
        //OfflineWebApplicationConnection owac = new OfflineWebApplicationConnection(newCred, ApplicationId, HealthServiceUrl + "wildcat.ashx", PersonInfo.PersonId);
        //WebApplicationConnection connection =
        //          new WebApplicationConnection(WebApplicationConfiguration.AppId,
        //                                       WebApplicationConfiguration.HealthServiceUrl,
        //                                       new WebApplicationCredential(WebApplicationConfiguration.AppId,
        //                                                                    authToken));
        //connection.Authenticate();

    }

}
public static class HealthVaultConnectionManager
{
    /// &lt;summary&gt;
    /// Creates Offline Web Application Connection
    /// &lt;/summary&gt;
    /// &lt;param name="applicationId"&gt;Application Id used for creating the offline connection&lt;/param&gt;
    /// &lt;param name="personId"&gt;Person Id who granted permission to perform operation&lt;/param&gt;
    /// &lt;returns&gt;Returns authentication connection&lt;/returns&gt;
    public static OfflineWebApplicationConnection CreateConnection(Guid applicationId,Guid personId)
    {
        OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(applicationId,
            WebApplicationConfiguration.HealthServiceUrl, personId);            
        offlineConn.Authenticate();
        return offlineConn;
    }

    /// &lt;summary&gt;
    /// Create Offline Web Application Connection
    /// &lt;/summary&gt;
    /// &lt;param name="applicationId"&gt;Application ID used for creating the offline connection&lt;/param&gt;
    /// &lt;returns&gt;reference to OfflineWebApplicationConnection &lt;/returns&gt;
    public static OfflineWebApplicationConnection CreateConnection(Guid applicationId)
    {
        OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(applicationId,
            WebApplicationConfiguration.HealthServiceUrl, Guid.Empty);
        offlineConn.Authenticate();
        return offlineConn;
    }
    public static WebApplicationConnection GetConnection(string wcToken)
    {
        WebApplicationConnection connection =
                   new WebApplicationConnection(WebApplicationConfiguration.AppId,
                                                WebApplicationConfiguration.HealthServiceUrl,
                                                new WebApplicationCredential(WebApplicationConfiguration.AppId,
                                                                             wcToken));
        connection.Authenticate();
        return connection;
    }

    public static string GetUserName(string wcToken)
    {
        WebApplicationConnection connection = GetConnection(wcToken);
        return (connection.GetPersonInfo().Name);
    }
}
</code></pre>

<p>This is redirect.aspx.cs code and its down side also mention web.config</p>

<pre><code>public partial class Redirect : Microsoft.Health.Web.HealthServiceActionPage
{
    //We don't want this page to require log on because when we sign out, 
    //we still want this page to read the WCPage_ActionSignOut key in the
    //Web.Config and redirect us to the proper page on sign out
    protected override bool LogOnRequired
    {
        get
        {
            return false;
        }
    }
}
</code></pre>
