I have a static HTML page that allows the user to log in and then call other web services to update content. The username and password are sent to a WCF REST service via JQuery. The login service looks like this:
[WebInvoke(UriTemplate = "", Method = "POST")]
public bool Login(ServiceUser user)
{
if(validCredentials(user)){
FormsAuthentication.SetAuthCookie(user.Username, true);
return true;
}
return false;
}
But before that happens, on page load I call another service to see if the user has already been authenticated. That service looks like this:
[WebGet(UriTemplate = "isAuthenticated")]
public bool IsAuthenticated()
{
return HttpContext.Current.User.Identity.IsAuthenticated;
}
That way, if they reload the page but have already logged in, I don’t prompt them for their password again.
The problem is that IsAuthenticated doesn’t seem to change it’s value unless I close and reopen the browser. Refreshing the page doesn’t change the value. Am I coding it wrong? Is it caching the value since it’s a WebGet?
Well, I think I was right that WebGet was caching it. I changed the IsAuthenticated service to use [WebInvoke(UriTemplate = “isAuthenticated”, Method = “POST”)] and it appears to be working correctly.