How to Capture HTTP Request of Static Files Deployed on IIS

When you release a JavaScript library, such as jQuery, online, you may need to collect some status information for analytics. If you deploy your website on IIS, you can use HTTP Module to capture HTTP requests of HTML, JS and CSS files. My goal is to make a statistic of how many times dynamsoft.webtwain.min.js is called.

Prerequisites

Capturing HTTP Request Event with HTTP Module

Create an empty wet site project in Visual Studio.

Add dynamsoft.webtwain.min.js file to the project.

Create a Class file in App_Code folder which is automatically generated.

Add the configuration to the web.config file.

Right-click the project root to publish the website. To build .cs files to a DLL file, check the following option.

The publish method is File System.

Deploy the project to IIS with 80 port.

Create an index.htm file for scanning documents. This file is deployed on another web server:

When someone visits the page in a web browser, there is a record generated on IIS.

Note: because of the cache mechanism, the JS file will not be reloaded unless you press Ctrl+F5 (Windows) or Command+Shift+R (macOS) in Chrome.

Using SQLite to Record Information of HTTP Request

A database is a better way of storing data than a text file. Let’s try SQLite.

Create a table:

Insert a record:

When running the website, I got the System.BadImageFormatException error.

The workaround is to use the 64-bit version of IIS Express.

To view the recorded data, use DB browser.

Source Code

https://github.com/yushulx/csharp-http-module

Originally published at www.codepool.biz on May 7, 2018.

Manager of Dynamsoft Open Source Projects | Tech Lover