【问题标题】:Getting notified when user exits browser in Silverlight application当用户在 Silverlight 应用程序中退出浏览器时收到通知
【发布时间】:2017-01-05 01:33:58
【问题描述】:

我有一个 Silverlight 应用程序,用户可以在其中登录。问题是某些用户可能根本不会注销。我想在我的申请中得到通知,以便我可以代表他注销。我一直在这里和那里浏览,但没有任何可行的解决方案。我找到的最相关的文章是这样的: How to notify an user when he tries to close a tab or close the browser 但无法得到结果。

谁能指出我,当用户退出应用程序页面或关闭我的应用程序中的浏览器时如何通知我?

【问题讨论】:

标签: c# silverlight browser


【解决方案1】:

也许使用 signal-R 的解决方法会起作用。

  1. 创建集线器并覆盖 OnDisconnected
  2. 在您的 silverlight 应用程序启动或登录时 - 连接到应用程序

如果用户关闭浏览器或选项卡,您将调用 OnDisconnected 方法。

以下是更多信息: https://www.codeproject.com/Tips/787033/SignalR-in-Silverlight

https://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server#onreconnected

【讨论】:

    【解决方案2】:

    将 Silverlight 控件包装在 ASP.NET 页面中,您可以调用应用程序 Unload 事件覆盖。

    protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
    }
    

    【讨论】:

      【解决方案3】:

      以下代码帮助我解决了我的问题

      public partial class App : Application
      {
          private MainPage mainPage;
          public App()
          {
              this.Startup += this.Application_Startup;
              this.Exit += this.Application_Exit;
              this.UnhandledException += this.Application_UnhandledException;
              InitializeComponent();
          }
      
          private void Application_Exit(object sender, EventArgs e)
          {
              //Log out the current user when application exits
              mainPage.LogoutCurrentUser();
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-16
        • 2021-11-23
        • 2011-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多