Skip to content Skip to sidebar Skip to footer

How To Check From Javascript If Loaded Page Has Asp.net Authentication Cookie?

It looks like JavaScript does not have access to authentication cookies ('ASP.NET_SessionId', '.ASPXFORMSAUTH') in the http headers I can see cookies but document.cookie object doe

Solution 1:

You could create a WebMethod which uses the following code to return a true/false value:

[WebMethod]
publicboolIsAuthenticated()
{
    return HttpRequest.IsAuthenticated;
}

Call this from javascript using jQuery or MSAJAX.

Solution 2:

ASP.NET session cookies are HTTP-only by default (and rightfully so). If you need to find out if the user is authenticated in Javascript, putting a HiddenField on the page and setting its value to 0 or 1 based on your authentication token is a much better solution.

Post a Comment for "How To Check From Javascript If Loaded Page Has Asp.net Authentication Cookie?"