Click here to Skip to main content
15,914,642 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionproject code in .net for online banking transaction Pin
Jk 0724-Aug-21 5:12
Jk 0724-Aug-21 5:12 
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 
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 
Sorry for all the trouble sir.

Please hang in there with me a little longer if you can.

I chose the path of least resistance by publishing and like you correctly stated, it generated .exe file.

I tried testing and ran into an error.

Please see how I was testing and the error:

C:\inetpub\wwwroot\showserverstatus\bin\publish>showserverstatus.exe google.com
IP Address: 2607:f8b0:4000:819::200e
RoundTrip time: 44

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at showserverstatus.Program.ServerStatusBy(String site) in C:\inetpub\wwwroot\showserverstatus\Program.cs:line 41
at showserverstatus.Program.Main(String[] args) in C:\inetpub\wwwroot\showserverstatus\Program.cs:line 16

As you can see, it displayed status of two lines before the error.

This is line 16:
foreach (string site in args)


and this is line 41:
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);


UPDATE:

My demo went well for the mere fact that this app actually ran and sent email was considered a success even though the email did not contain anything.

Here is why.

Due to the error I was getting that I posted above, I removed all of those reply.stuff and then just left only DOWN or WORKING.

They wanted them worded as those.

Per the changes I made below, the app ran and sent the email but when I received the email, there was no message that site is WORKING or DOWN.

Is it because of the changes by replacing Subject with hardcoded values and body with hardcoded values?


They also brought up something that I overlooked.

They wanted Subject to read: Server Status

They wanted the body to read:

Please find the status of the DMZ servers below:


whatever site name is - working or Down (Whatever the status is).
This is latest code.

Please, please forgive me sir for all these troubles. Looks like we are almost there.


I changed the code below to format them just as described above.

The only issue now and it is a big one is that it works with pretty much any URL I tested with except anything that begins with gis.

For instance, none of these worked:

https://gis.massdot.state.ma.us/arcgis/rest
gis.massdot.state.ma.us/arcgis/rest/
gis.massdot.state.ma.us/arcgis/rest

PHP
using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Text;
using System.Configuration;
using System.Collections.Generic;

namespace showserverstatus
{
    class Program
    {
        static void Main(string[] args)
        {
            var siteToStatus = new Dictionary<string, string>();
            foreach (var site in args)
            {
                var reply = new Ping().Send(site, 10000);
                siteToStatus[site] = (reply.Status == IPStatus.Success) ? "UP" : "DOWN";
            }
            var subject = "Server Status";
            var body = "Please find the status of the servers below:";
            foreach (var kvp in siteToStatus)
            {
                body += $"{Environment.NewLine}{kvp.Key}: {kvp.Value}";
            }
            SendEmail(subject, body);
        }

        static bool ServerStatusBy(string site)
        {
            Ping pingSender = new();
            PingReply reply = pingSender.Send(site, 10000);
            if (reply.Status != IPStatus.Success)
            {
                SendEmail($"{site} DOWN", $"Ping {site}");
                return false;
            }
            SendEmail($"{site} WORKING", $@"Ping {site}");

            return true;
        }
        public static void SendEmail(string subject, string body)
        {
            using MailMessage mm = new(ConfigurationManager.AppSettings["FromEmail"], "joeblow@yahoo.com");
            mm.To.Add("johndoe@gmail.com");
            mm.CC.Add("joesixpack@yahoo.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);
        }
    }
}


modified 26-Aug-21 23:19pm.

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 

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.