title: Trigger confirmation message box during asp.net LoggingIn event
body: <p>I have a web application in vb in which I am using <a href="http://geekswithblogs.net/Frez/archive/2010/05/17/preventing-a-user-from-having-multiple-concurrent-sessions.aspx" rel="nofollow">this approach</a> to prevent a user from having concurrent logins due to a simple licensing agreement. </p>
  
  <p>It works great, if a user logs in with an account that is already in use, the first user gets logged out.  I am trying to add a messagebox or some kind of js confirmation box in the loggingin event that states:</p>
  
  <pre><code>This user account has been active in the last 20 minutes.
  If someone else is using it, then logging in may possibly
  compromise any report generation or activity.
  Continue login?
  </code></pre>
  
  <hr>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;asp:Login ID="Login1" runat="server"  DestinationPageUrl="~/Dashboard/Default.aspx" &gt;
      &lt;LayoutTemplate&gt;
          &lt;table border="0" cellpadding="0"&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;&lt;p&gt;&lt;asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName"&gt;User Name:&lt;/asp:Label&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;td align="right"&gt;
                      &lt;p&gt;&lt;asp:TextBox ID="UserName" runat="server" Width="220" autocomplete="on" /&gt;
                      &lt;asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" Text="*"
                          ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1" /&gt;&lt;/p&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;&lt;p&gt;&lt;asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password"&gt;Password:&lt;/asp:Label&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;td align="right"&gt;
                      &lt;p&gt;&lt;asp:TextBox ID="Password" runat="server" TextMode="Password" Width="220"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" Text="*"
                          ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1" /&gt;&lt;/p&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="center" colspan="2" style="color: red"&gt;&lt;asp:Literal ID="FailureText" runat="server" EnableViewState="False"&gt;&lt;/asp:Literal&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right" colspan="2"&gt;&lt;asp:LinkButton CssClass="prettyButton" ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1"  /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/LayoutTemplate&gt;
  &lt;/asp:Login&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub Login1_LoggingIn(sender As Object, e As LoginCancelEventArgs) Handles Login1.LoggingIn
  
          Dim messagetext As String = "This user account has been active in the last 20 minutes." + Environment.NewLine + Environment.NewLine
          messagetext += "If someone else is using it, then logging in may possibly" + Environment.NewLine
          messagetext += "compromise any report generation or activity." + Environment.NewLine + Environment.NewLine
          messagetext += "Continue login?"
  
          Dim userNameTextBox As System.Web.UI.WebControls.TextBox = DirectCast(Login1.FindControl("UserName"), System.Web.UI.WebControls.TextBox)
          Dim currentUser As MembershipUser = Membership.GetUser(userNameTextBox.Text)
  
          If currentUser IsNot Nothing Then
              If currentUser.IsOnline Then
  
               '*****CONFIRMATION MESSAGE BOX TO GO HERE*****/
               Dim result = MessageBox.Show(messagetext , "Login Warning", MessageBoxButtons.YesNo)
  
               '* IF USER DECIDES NOT TO LOGIN:*/
               If result = DialogResult.No Then
                  e.Cancel = True
               End If
  
               '* ELSE LOGIN CONTINUES AND ORIGINAL USER IS LOGGED OUT*/
              End If
          End If
      End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub Login1_LoggedIn(sender As Object, e As EventArgs) Handles Login1.LoggedIn
          Dim userNameTextBox As System.Web.UI.WebControls.TextBox = DirectCast(Login1.FindControl("UserName"), System.Web.UI.WebControls.TextBox)
          SingleSessionPreparation.CreateAndStoreSessionToken(userNameTextBox.Text)
      End Sub
  </code></pre>
  
  <hr>
  
  <p>Now, I can use a windows form <code>msgbox()</code> locally, and everything works great, but once I put it on a server, the message box obviously doesn't work.  I've tried <code>ClientScript</code> and <code>ScriptManager</code>, but the client side check doesn't seem to get triggered.</p>
  
  <p>Any help is greatly appreciated.</p>