1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
<script RunAt="server">
public static int nbUsers;
void Application_Start(object sender, EventArgs e)
{
nbUsers = 0;
}
void Application_End(object sender, EventArgs e)
{}
void Application_Error(object sender, EventArgs e)
{}
void Session_Start(object sender, EventArgs e)
{
nbUsers++;
if (nbUsers >= 30)
{
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("aaa@aaa.com");
mail.To.Add("aaa@aaa.com");
//set the content
mail.Subject = "Number of concurrent connections";
mail.Body = "(" + DateTime.Now + ") IP Connected : " + HttpContext.Current.Request.UserHostAddress.ToString() + " Total number now : " + nbUsers.ToString();
//send the message
SmtpClient smtp = new SmtpClient("mail.aaa.com");
NetworkCredential Credentials = new NetworkCredential("aaa@aaa.com", "########");
smtp.Credentials = Credentials;
smtp.Send(mail);
}
}
void Session_End(object sender, EventArgs e)
{
nbUsers--;
}
</script> |
Partager