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#.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.