This DLL will enable an IIS website to redirect all requests to the home page when there are requests for EXE, RAR, Zip files that have no reference or have a reference from outside of your own web site. For example, if someone tries to download http://www.yoursite.com/download/dd.exe by clicking on that link from another site, they will be redirected to http://www.yoursite.com/.
A few days ago, I discovered that 80% of the traffic to my website is to download an EXE file which I give as a free download on the Internet. After check with the page view traffic, I found that users were downloading the EXE file without even looking at my web page. I did some search on the Internet and realised there are no free tools to stop this and to find the difference between direct download from a link in another site and download from my own website. I decided to write an HTTP filter to do this.
Key knowledge: When downloading a file from your website by clicking on a link from another website, the page will have an
HTTP_Reference value which has the name of the other website. For example, if someone tries to download http://www.arcai.com/download/netcut.exe by clicking on that link from http://www.othersite.com/downloadlink.html, then the HTTP request to your website will come with a
If someone tries to download files directly (not from another web page), the
HTTP_REFERRE will be empty. And, if someone tries to download http://www.arcai.com/download/netcut.exe by clicking on a link from your own website, then the
HTTP_REFERER will have your website's URL.
This can be detected by programming on the HTTP FILTER DLL project.
So, a few hours later, this project was released. It is very simple: a one line fix to the source code of the default ISAPI project of VC++ 2003. Actually, only one virtual function has been overwritten. No configuration is needed to use this tool. I had this tool enabled on one of my sites with in a second after its release. And, it has been running very well. Here is a demo. Click on the link, and you will be taken to http://www.arcai.com/, and from there, click on the download link, and you can then download the file.
Using the code
There are two parts that were modified in the default CHttpFilter project.
- I addrf a
dwflags, so our
OnUrlMap will be run.
BOOL CNoDirectExeFilter::GetFilterVersion(PHTTP_FILTER_VERSION pVer)
pVer->dwFlags &= ~SF_NOTIFY_ORDER_MASK;
pVer->dwFlags |= SF_NOTIFY_SECURE_PORT | SF_NOTIFY_NONSECURE_PORT |
SF_NOTIFY_END_OF_NET_SESSION | SF_NOTIFY_URL_MAP;
pVer->dwFlags |= SF_NOTIFY_ORDER_LOW;
IDS_FILTER, sz, SF_MAX_FILTER_DESC_LEN));
- We overwrite a virtual function
OnUrlMap. This function checks all the HTTP requests, and deals with all requests for EXE, zip, and RAR files (you can add more file extensions to the source code by simply fixing it).
DWORD CNoDirectExeFilter::OnUrlMap(CHttpFilterContext* pfc,
dwSize = sizeof(szAddress);
if (pfc->GetServerVariable("HTTP_REFERER", szAddress, &dwSize))
dwSize = sizeof(szAddress);
if(pfc->GetServerVariable("SERVER_NAME", szAddress, &dwSize))
CHAR szRedirect ;
sprintf(szRedirect, "Location: http://%s\r\n\r\n", ServerName.GetBuffer(0));
pfc->ServerSupportFunction ( SF_REQ_SEND_RESPONSE_HEADER,
(LPVOID) "302 Redirect",
(DWORD *) szRedirect,
return CHttpFilter::OnUrlMap(pfc, pUrlMap);
How to use
- Download the ready-to-use DLL file, and unzip the files into any folder accessible by IIS, like C:\winnt\system32\.
- Go to the ISAPI filter setting of the website which you want to enable these features.
- Click on the Add button and select nodirectexe.dll.
- Restart W3SVC.
Now, all your EXE, zip, and RAR files are under the protection of this DLL. All direct downloads and downloads by click on links other than that on your own website will be redirected to your front page URL.
Points of interest
Do it yourself sometime is the only and the best way. Oh, you will need C++ !!.
This is first time release. My home Page will have a more recent version released.