如何知道浏览器在C#中已关闭 [英] How to know Browser is closed in c#

查看:179
本文介绍了如何知道浏览器在C#中已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道何时使用C#或ASP.NET在客户端关闭浏览器,因为我想更新数据库中用户的登录状态.
朋友,那些链接很好,但是我不想使用javascript或jQuery,我想在C#或ASP.NET中使用纯解决方案(使用服务器端控件)

在此先感谢:-)

I want to know when browser is closed on client side using C# or in ASP.NET as I want to update the login status of the user in Database.
Hi Friends those links are good but I do not want to use javascript or jQuery I want Solution purly in C# or ASP.NET(using Server side control)

Thanks in Advance :-)

推荐答案

也许其中之一可以为您提供帮助-

http://www.dotnetspider.com/resources/30715-处理浏览器关闭事件在服务器端Side.aspx [ http://weblogs.asp.net/kodali/archive/2010/04/29/asp-net-session-on-browser-close.aspx [ http://forums.asp.net/p/1153888/1891072.aspx [ ^ ]
Maybe one of these can help you -

http://www.dotnetspider.com/resources/30715-Handling-Browser-Close-Event-at-Server-Side.aspx[^]
http://weblogs.asp.net/kodali/archive/2010/04/29/asp-net-session-on-browser-close.aspx[^]
http://forums.asp.net/p/1153888/1891072.aspx[^]


朋友,这些链接很好,但我不想使用javascript或jQuery,我希望在C#或ASP.NET中使用纯解决方案(使用服务器端控件)

这是不可能的-浏览器是客户端软件.

您的服务器正在运行您的C#代码.服务器如何知道客户端已做某事?它不能订阅客户端事件",这恰恰是关闭浏览器的目的.

取而代之的是,由您的设计决定浏览器是否通知服务器已发生事件. *您需要在客户端上运行一些代码以通知服务器*

您在这里的选择是有限的. Javascript是显而易见的选择,因为它与跨浏览器兼容,并且您将有很大的几率启用它.

我见过的一种解决方案是让javascript订阅客户端上的"onclosing"事件,并在事件处理程序中调用网络服务以告知服务器我"已关闭浏览器窗口''
Hi Friends those links are good but I do not want to use javascript or jQuery I want Solution purly in C# or ASP.NET(using Server side control)

It''s impossible - The browser is a client piece of software.

Your server is running your C# code. How is the server ever going to know that the client has done something? It can''t subscribe to ''client events'', which is exactly what closing the browser is.

Instead, it''s up to your design to make the browser inform the server that an event has taken place. *You need to run some code on the client to inform the server*

Your options here are limited. Javascript is the obvious choice, because it''s cross browser compatible and you''ve a fairly high % chance that it''s going to be enabled.

A solution I''ve seen used for this is to have javascript subscribe to the ''onclosing'' event on the client, and call a web service in the event handler to tell the server ''I''ve closed the browser window''


这篇关于如何知道浏览器在C#中已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆