I have a web service call in my function Verify
.
The code is as follows:
public async Task<ActionResult> Index()
{
....
UserContext.LoginUser = null;
if (!string.IsNullOrEmpty(etoken))
{
SSOLogin ssoLogin = new SSOLogin();
LoginUser user = await ssoLogin.Verify(etoken);
UserContext.LoginUser = user;
if (UserContext.LoginUser == null)
return RedirectToAction("UnAuthorized", "Login");
else
{
Session["authenticated"] = true;
userId = UserContext.LoginUser.UserId;
domain = UserContext.LoginUser.Domain;
}
}
}
public async Task<LoginUser> Verify(string etoken)
{
string publicKey = "xxx";
LoginUser loginUser = null;
WSVerifyAccessToken wsVerifyAccessToken = new WSVerifyAccessToken();
string verifyResponse = await wsVerifyAccessToken.VerifyAccessToken(etoken); // Inside, this is a web service call
if (!string.IsNullOrEmpty(verifyResponse))
{
/* Some processing here */
}
return loginUser;
}
The problem is that, the UserContext becomes null after the Verify
function
LoginUser user = await ssoLogin.Verify(etoken);
Hence when I assign
UserContext.LoginUser = user;
gives me the error System.NullReferenceException: Object reference not set to an instance of an object.
.
I tried to make the function to be synchronous
LoginUser user = await ssoLogin.Verify(etoken).Result;
but then the web service call will just hang there and never finishes.
Any solution?