locked
is it a valid approach to implement a network scanning service as an action method that will be called from external systems RRS feed

  • Question

  • User-540818677 posted

    I am working on an asp.net mvc 5 web application which represents an ERP system , and i deployed under iis7. And now I want to implement a new scanning service, which mainly uses powercli and power shell scripts, and scan our network for servers & vms and get their specifications and their statues.

    So I am thinking of the following approach:-

    1. Since the scanning should be access by only specific users and requires the hosting server to have powercli and other tools installed, so I want to create a new asp.net mvc 5 web application , and deploy it under iis7 instead of modifying my current ERP system,. Where the new application will have the following action method which will do the scan as follow:-

    public ActionResult ScanServer(string token)
            {
    // do the scan
    //send n email with scanning result
    }

    2 .Now inside my current ERP system I can manually initiating the scan by calling the above action method as follow:-

      [HttpPost]
           [CheckUserPermissions(Action = "", Model = "Admin")]
           public ActionResult Scan()
           {
               try
               {
    
                   string currentURL = System.Web.Configuration.WebConfigurationManager.AppSettings["scanningURL"];
                   using (WebClient wc = new WebClient())
                   {
                       string url = currentURL + "home/scanserver?token=*******" ;
                       var json = wc.DownloadString(url);
                       TempData["messagePartial"] = string.Format("Scan has been completed. Scan reported generated");
    
                   }
    
    
    
    
               }
               catch (WebException ex)
               {
                   TempData["messageDangerPartial"] = string.Format("scanningservice can not be accessed");
    
    
    
               }
               catch (Exception e)
               {
                   TempData["messageDangerPartial"] = string.Format("scan can not be completed");
    
    
    
               }

    Now I did a quick test where I manually started the scan from the ERP and the scanning service deployed under iis worked well.

    But I have these questions:-

    1. The scanning service might take 20-30 minutes to complete. So from an architecture point of view is my current approach considered valid ? I mean to initiate a scan by calling an action method from another application ?

    2. Now can i inside the scanning service web application, to force it to call its action method on a timely basis (for example every 4 hours)?

    Thanks

    Thursday, September 3, 2015 11:54 AM

All replies

  • User-1611549905 posted

    You'll be better off using a separate console application or a Windows service to do this (or any other long-running task).

    Friday, September 4, 2015 7:23 AM
  • User-540818677 posted

    You'll be better off using a separate console application or a Windows service to do this (or any other long-running task).

    can you adivce why i should avoid having asp.net mvc web application that exposes one of its action method to do a network scan ? i mean this how web services works , you call a web service and wait for the reply .. also i worked with SharePoint 2013, where you can for example start a full crawl search from your browser, or re-index your search by clicking on a button inside your browser ,, and the screen keeps loading for around 30 minutes till the full search and the re-index finishes .. so does this mean that this approach used by SharePoint is not 100& robust ?

    Friday, September 4, 2015 7:32 AM
  • User-1611549905 posted

    If it's an MVC application it'll usually be running in the context of IIS -- in an IIS application pool. This is not a suitable environment for long-running processes because IIS app pools are not guaranteed to hang around indefinitely. They can be recycled for a whole variety of reasons -- if they consume too much memory, or if they are idle for a certain length of time, or if a thread throws an unhandled exception for example.

    Programs such as SharePoint that need to run long-running tasks generally run them in a separate process -- either a console app or a Windows service depending on your requirements. They communicate with your MVC front end using one of a number of different approaches such as MSMQ, WebSockets (SignalR) or good old-fashioned polling and database updates.

    Friday, September 4, 2015 8:36 AM
  • User-488622176 posted

    using web pages for long running processes is a bad idea. You simply block the webserver queue. It was not designed for this. What you could do : create a web service (web api, ...) that launches a request to an async process (ex: Windows service, ...) and periodically check (async !) the status of the request. Meaning : html5 page, launch request to service, service queues request in Windows Service (long running process), and returns process id. in your HTML5 app you periodically check the status of the request with given id.

    Friday, September 4, 2015 9:49 AM
  • User-540818677 posted

    using web pages for long running processes is a bad idea. You simply block the webserver queue. It was not designed for this. What you could do : create a web service (web api, ...) that launches a request to an async process (ex: Windows service, ...) and periodically check (async !) the status of the request. Meaning : html5 page, launch request to service, service queues request in Windows Service (long running process), and returns process id. in your HTML5 app you periodically check the status of the request with given id.

    Thanks for the reply. but in my case the asp.net mvc web application which will do the scan will be on a separate VM and hosted on a separate IIS . and i will be calling it using WebClinet  from external applications, as follow:-

    public ActionResult CallTheScanService()
           {
               try
               {
    
                  
                   using (WebClient wc = new WebClient())
                   {
                       string url = currentURL + "home/scanserver?tokenfromtms=" + "12345" + "&FQDN=allscan" ;
                       var json = wc.DownloadString(url);
                       TempData["messagePartial"] = string.Format("Scan has been completed. Scan reported generated");
                      
                   }
    
    
    
    
               }
              //code goes here..
               return PartialView(repository.getlatestScan(10));
           }

    so let say i have an ERP system which will call the ScanningService using the above action method. in this case the IIS which hosts the ERP system will not got interpreted by the scan & the above action method will only consume one thread from the IIS till it gets a reply from the scanning service (the json object is retuned) is this correct ?

    second question . now on my scanning service itself  i define the following inside its global.asc to call its own action method every 1 hour to do a scheduled scan:-

    public class MvcApplication : System.Web.HttpApplication
        {
    
    
            static void ScheduleTaskTrigger()
            {
                HttpRuntime.Cache.Add("ScheduledTaskTrigger",
                                      string.Empty,
                                      null,
                                      Cache.NoAbsoluteExpiration,
                                      TimeSpan.FromMinutes(60), // Every 1 hour
                                      CacheItemPriority.NotRemovable,
                                      new CacheItemRemovedCallback(PerformScheduledTasks));
            }
    
            static void PerformScheduledTasks(string key, Object value, CacheItemRemovedReason reason)
            {
               
               HomeController h = new HomeController();
               var c = h.ScanServer("***", "scan");
                ScheduleTaskTrigger();
            }
    
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
    
                WebApiConfig.Register(GlobalConfiguration.Configuration);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
    
                ScheduleTaskTrigger();
               
            }
        }

    so mainly i am calling its action method "h.ScanServer("***", "scan");" every 1 hour, so now whenthe scan service is being called from the global.asc file this will not reach the iis is this correct ? as 95% of the time no one are going to run the manual scan from  the web browser  by calling the above action method , and they will wait for the scan schedule to run as defined inside the scanning service global.asc .. can you adivce ?

    Friday, September 4, 2015 11:26 AM