Comme d'autres l'ont dit, le ticket d'authentification est et DEVRAIT être httponly.
La meilleure façon d'y parvenir est d'utiliser ApplicationServices. Le point de terminaison d'authentification JSON expose IsLoggedIn et j'ai remarqué votre préoccupation concernant la charge du serveur. La surcharge d'un appel à un point de terminaison statique qui vérifie simplement le cookie pour vous est négligeable. Vraiment. Donc, si vous utilisez MsAjax, activez les services d'application et appelez Sys.Services.AuthenticationService.IsLoggedIn.
Si vous voulez faire de javascript brut est ici la codez ;-)
Ajouter ce segment à vous de fichier config
<system.web>
------------
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled ="true" requireSSL="false"/>
</webServices>
</scripting>
</system.web.extensions>
La page ....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function createXHR() {
// a memoizing XMLHttpRequest factory.
var xhr;
var factories = [
function() { return new XMLHttpRequest(); },
function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
function() { return new ActiveXObject("Msxml3.XMLHTTP"); },
function() { return new ActiveXObject("Microsoft.XMLHTTP"); } ];
for (var i = 0; i < factories.length; i++) {
try {
xhr = factories[i]();
// memoize the factory so we don't have to look for it again.
createXHR = factories[i];
return xhr;
} catch (e) { }
}
}
function isLoggedIn() {
var xhr = createXHR();
xhr.open("POST", "/Authentication_JSON_AppService.axd/IsLoggedIn", true);
xhr.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status != 200) {
alert(xhr.statusText);
} else {
alert("IsLoggedIn = " + xhr.responseText);
}
xhr = null;
}
};
xhr.setRequestHeader("content-type", "application/json");
xhr.send(null);
}
</script>
</head>
<body>
<input type="button" value="IsLoggedIn?" onclick="isLoggedIn()" />
</body>
</html>
@pavlo, vous pouvez vérifier à partir du client. il y a un mécanisme spécifiquement conçu pour que ma MS fasse exactement cela à partir du script client. Il est propre et rapide, il n'y a pas d'activité de disque, il lit juste le cookie pour vous et renvoie un booléen.vois ma réponse avant d'abandonner. –