Steve Kiss
Steve Kiss

Reputation: 1118

Knowing a file was accessed IIS

I need to be able to know when a file is accessed on an IIS server. In other words, I have a folder where a bunch of files are placed for users to download. Is there a way for me to know when one of these files is accessed? I am using C#.

Upvotes: 1

Views: 334

Answers (2)

Wyatt Barnett
Wyatt Barnett

Reputation: 15663

IIS log parsing is the way to go here. And with the IIS log parser it is disturbingly easy. You could also use most of the old-style offline web log parsers if you needed decent reporting on this.

Upvotes: 0

ChrisLively
ChrisLively

Reputation: 88072

You could always parse the IIS logs to find out when a file was accessed, by whom (within limits), and how long the transfer took.

Alternatively, you could write an HttpModule or HttpHandler that would handle the file download calls, and log it on access.

Going the HttpModule route, it could be injected now without worrying about changing the links to the files themselves. A HttpHandler would require changing the links to the files.

Regardless utilizing IIS logging, as suggested by @john saunders in the comments is probably the best bet. You can tell IIS to log to store the logging information in a database then run sql queries against that logging table to show real time accesses.

Upvotes: 4

Related Questions