Click here to Skip to main content
15,913,709 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: project code in .net for online banking transaction Pin
Richard MacCutchan24-Aug-21 5:40
mveRichard MacCutchan24-Aug-21 5:40 
GeneralRe: project code in .net for online banking transaction Pin
Member 1534301831-Aug-21 22:04
Member 1534301831-Aug-21 22:04 
QuestionI am having problem creating a script to monitor Rest/API services. Pin
samflex23-Aug-21 8:11
samflex23-Aug-21 8:11 
AnswerRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming23-Aug-21 21:15
mveRichard Deeming23-Aug-21 21:15 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex24-Aug-21 5:08
samflex24-Aug-21 5:08 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
David Mujica24-Aug-21 6:04
David Mujica24-Aug-21 6:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex24-Aug-21 6:09
samflex24-Aug-21 6:09 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 4:18
samflex25-Aug-21 4:18 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
David Mujica25-Aug-21 5:24
David Mujica25-Aug-21 5:24 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 6:09
samflex25-Aug-21 6:09 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming25-Aug-21 6:18
mveRichard Deeming25-Aug-21 6:18 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex25-Aug-21 8:23
samflex25-Aug-21 8:23 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming25-Aug-21 22:12
mveRichard Deeming25-Aug-21 22:12 
1. It looks like you've already answered that one. Smile | :)

2. Yes, you'd set the application to be the full path to your .exe file, and the command-line arguments to be the list of domains you want to test.

3. You can pass as many domains to test as you want as command-line arguments.


samflex wrote:
C#
if (reply.Status != IPStatus.Success)
{
    Console.WriteLine("{0}: {1}", site, reply.Status);
    string statusMessage = "Shw message that Server is down"; //Dont know if I am doing this correctly.
    SendEmail(); // Send out email when server is down
    return false;

}
else
    statusMessage = "Shw message that Server is up"; //Dont know if I am doing this correctly.
A couple of problems there:

Within the if block, you've created a local variable called statusMessage, which hides the static field of the same name. The value you store in the local variable won't be visible to the SendEmail function.

You don't need the else, since you've got a return within the if block.

samflex wrote:
C#
Console.WriteLine("Email Sent.");
System.Threading.Thread.Sleep(3000);
Environment.Exit(0);
You shouldn't call Environment.Exit within the SendEmail function, since that will terminate your app after the first message is sent.

I'd avoid using a field, and pass the message subject and body as parameters to the SendEmail function instead.
C#
public static void SendEmail(string subject, string body)
{
    using MailMessage mm = new(ConfigurationManager.AppSettings["FromEmail"], "joe.blow@yahoo.com");
    mm.To.Add("joesixpack@gmail.com");
    mm.CC.Add("jandoe@gmail.com");
    mm.Subject = subject;
    mm.Body = body;
    mm.IsBodyHtml = false;
    
    SmtpClient smtp = new()
    {
        Host = ConfigurationManager.AppSettings["Host"],
        Port = int.Parse(ConfigurationManager.AppSettings["Port"]),
        EnableSsl = true,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]),
    };
    
    Console.WriteLine("Sending email...");
    smtp.Send(mm);
    Console.WriteLine("Email sent.");
    System.Threading.Thread.Sleep(3000);
}
C#
static bool ServerStatusBy(string site)
{
    Ping pingSender = new();
    PingReply reply = pingSender.Send(site, 10000);
    if (reply.Status != IPStatus.Success)
    {
        Console.WriteLine("{0}: {1}", site, reply.Status);
        SendEmail($"{site} DOWN", $"Ping {site} returned {reply.Status}.");
        return false;
    }
    
    Console.WriteLine("IP Address: {0}", reply.Address);
    Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
    Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
    Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
    Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
    
    SendEmail($"{site} Up", $@"Ping {site}
IP Address: {reply.Address}
RoundTrip time: {reply.RoundtripTime}
Time to live: {reply.Options.Ttl}
Don't fragment: {reply.Options.DontFragment}
Buffer size: {reply.Buffer.Length}");
    
    return true;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 3:04
samflex26-Aug-21 3:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 3:52
mveRichard Deeming26-Aug-21 3:52 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 4:04
samflex26-Aug-21 4:04 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 5:08
samflex26-Aug-21 5:08 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 5:19
mveRichard Deeming26-Aug-21 5:19 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex26-Aug-21 6:41
samflex26-Aug-21 6:41 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming26-Aug-21 21:28
mveRichard Deeming26-Aug-21 21:28 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
samflex27-Aug-21 3:21
samflex27-Aug-21 3:21 
GeneralRe: I am having problem creating a script to monitor Rest/API services. Pin
Richard Deeming27-Aug-21 4:10
mveRichard Deeming27-Aug-21 4:10 
General(SOLVED) Re: I am having problem creating a script to monitor Rest/API services. Pin
samflex27-Aug-21 5:27
samflex27-Aug-21 5:27 
QuestionBest, cheap, ASP.NET Core hosting? Pin
Chris Maunder4-Aug-21 8:36
cofounderChris Maunder4-Aug-21 8:36 
AnswerRe: Best, cheap, ASP.NET Core hosting? Pin
jkirkerx11-Aug-21 11:15
professionaljkirkerx11-Aug-21 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.