WIF を実装した Azure でアプリケーションを公開しました。また、その Web アプリケーションに関連付けられた Web ジョブもあります。
ユーザーは WebApplication にログインしますが、WebJob でログイン ユーザーの詳細を取得できません。
WebJob は User の Details を取得し、DB と Blob に格納することを想定しています。
WebJob の次のコードはエラーを返します -
private string GetLoggedinUser()
{
string givenName = string.Empty;
IClaimsPrincipal claimsPrincipal = HttpContext.Current.User as IClaimsPrincipal;
IClaimsIdentity claimsIdentity = claimsPrincipal.Identity as IClaimsIdentity;
if (claimsIdentity != null)
{
givenName = (from c in claimsIdentity.Claims
where c.ClaimType == ClaimTypes.GivenName
select c.Value).Single();
}
return givenName;
}
上記のコードは、「オブジェクトが参照されていません」というエラーをスローします。つまり、「HttpContext.Current」でnullオブジェクトエラーが発生します