开发者

logout user in onbeforeunload and send log to server

开发者 https://www.devze.com 2023-04-01 12:57 出处:网络
I\'m running a silverlight web app and I want to log the user out if he closes the browser, change site etc. in case they forget to click the logout button and I want to do this in the web page that h

I'm running a silverlight web app and I want to log the user out if he closes the browser, change site etc. in case they forget to click the logout button and I want to do this in the web page that hosts the silverlight.

I tried following a tutorial: adding webservice.htc and calling the web service using javascript which looks like this

html body tag:

<body id="service" style="behavior:url(webservice.htc)">

script:

window.onbeforeunload = function(){
   // set web service
   service.useService(
   "https://myhost/myService/service.svc?wsdl",
   "myService");

   // call web service method
   service.myService.callService("LogInUser", -1);
}

the onbeforeunload does get called if i just try to show a message like

return "onbeforeunload called!";

EDIT: My web service is in SOAP an开发者_StackOverflow中文版d would like to consume in using javascript or or another option in my ASP.net 3.5 hosting the silverlight and is supposed to be viewed in IE8+. Any options that could complete this?


I'm not familiar with the method you show, but I assume the document simply gets unloaded before anything can happen in your web service.

The only cross-browser way to do this that I know of is to make a synchronous Ajax call. More here, or in jQuery use the async: false flag.

I'm not sure whether this is a good idea at all though. For example, a user might have the same session open in a different browser window. With your method, closing one of them will log them out of both of them. Also, a synchronous Ajax request can freeze the browser if the network goes down.

0

精彩评论

暂无评论...
验证码 换一张
取 消