-5

I am trying to automate the cleanup of legacy/heritage code and I can identify current resources in use from IIS logs but server side pages like .ASP and .PHP have include chains which I would like to be able to identify via code (C#)

In order to narrow the question down as it was too broad ...

  • OS - Windows 10
  • Web Server - IIS
  • Preferred language - C#
  • Example - any IIS served website

I have code that reads IIS log files where I have identified all static served resources including the initial .ASP or .PHP pages.

I required some accompanying C# code to also detail any .ASP or .PHP included files that were processed on the server and therefore do not appear in the IIS logs.

As it happens I have found the solution and provided an answer below.

I hope this is enough detail to take this off 'On Hold'

Jay Byford-Rew
  • 5,736
  • 1
  • 35
  • 36
  • Php allows user mappings of class names to file paths (autoloading) via spl_autoload_register in any which way. Otherwise I'd say look for include/require(_once) lines. – Progrock Jan 05 '17 at 10:59
  • Off-topic : http://stackoverflow.com/help/on-topic – CD001 Jan 05 '17 at 11:00
  • 1
    Won't cover everything, but recent last access file times? – Progrock Jan 05 '17 at 11:01
  • 1
    To make this question more on topic, give an example of code/processes you've tried so far, expected outcomes and what works and doesn't for you. – Progrock Jan 05 '17 at 11:01

1 Answers1

0

Many thanks to @Progrock for pointing me to checking last accessed time for files in target folder. This is what I had to do.

Ensure capturing last accessed time is being set by Windows (see Directory.GetFiles keeping the last access time)

Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();

Also need to restart IIS to stop any cached in memory files

Process.Start("IISRESET").WaitForExit();

A refresh on FileInfo needs to be performed to ensure you get the correct last accessed time (see How can System.IO.FileSystemInfo.Refresh be used).

This resulted in the following code ...

var start = DateTime.UtcNow;
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Process.Start("IISRESET").WaitForExit();
//do work that will access folder. i.e. access IIS web pages
var files = Directory.GetFiles(iisPath, "*.*", SearchOption.AllDirectories).ToList();
files = files.Where(x =>
{
  var fileInfo = new FileInfo(x);
  fileInfo.Refresh();
  return fileInfo.LastAccessTimeUtc >= start;
}).ToList();   

I can use this list of files to identify all .ASP and .PHP and any other files that were accessed via the IIS server on page requests.

Community
  • 1
  • 1
Jay Byford-Rew
  • 5,736
  • 1
  • 35
  • 36