AuthFilt demonstrates how to write an authentication filter based on an external datasource. Authentication is the process of accepting or denying a request from a client, so AuthFilt will be notified each time an authentication request comes in.
Warning If you install this ISAPI filter on your server, make sure that you have configured IIS to restrict access to the virtual directory that contains the filter and the files you want to transmit. Also, set proper access control on the files in their physical folder. For more information, click Start, Help and Support, and search for Access Control.
Important These samples are provided for educational purposes only. They are not intended to be used in a production environment, have not been tested in a production environment, and Microsoft does not provide technical support for them.
Sample Overview
Requirements
Location of the Source Code
Build and Install the Sample
Run the Sample
Sample Output
Helpdesk
This sample uses a file (c:\inetsrv\userdb.txt) to keep track of authorized users, but it might be modified to access a database which holds user info. The file c:\inetsrv\userdb.txt does not exist. Please look at Db.c to see how to construct such a file and change the location of the file if you so desire.
For each authentication request, AuthFilt first looks in a cache of recently authenticated users, and when that fails, AuthFilt looks in the userdb.txt file. This shows an efficient way to authorize connections: a cache allows the filter to quickly authenticate users, and because each request comes in through the filter, speed is critical.
to top
This sample requires the installation of the following software to function properly:
IIS samples are included in the IIS Software Developer Kit (SDK). You can download the IIS SDK from Platform SDK Update. You can view the SDK at MSDN Online. In the table of contents at MSDN Online, click Web Development, Server Technologies, Internet Information Services (IIS), SDK Documentation, Internet Information Services, Samples.
The following source code files are required for this sample:
File | Description |
---|---|
AuthFilt.sln | AuthFilt Visual Studio .NET solution file, required to build this sample in Visual Studio .NET. |
AuthFilt.vcproj | AuthFilt Visual Studio .NET C Project file, required to build this sample in Visual Studio .NET. |
AuthFilt.dsp, AuthFilt.dsw | AuthFilt Visual Studio Version 6 project files, required to build this sample in Visual Studio Version 6. |
AuthFilt.c | The main C source file |
cache.c | C functions for username/password caching |
db.c | C functions for username/password storage |
AuthFilt.h | AuthFilt header file |
AuthFilt.htm | AuthFilt Web page that uses AuthFilt filter for authentication. |
MAKEFILE | CTETest makefile for command line compilation |
To build this sample using the Visual C++ IDE, the following steps must be performed:
To build and run this sample without using the Visual C++ IDE, the following steps must be performed:
C:\MySamples
, type the following at the command line:
cd /d c:\MySamples NMAKE All
To install this sample, the following steps must be performed:
C:\Samples
and copy the files to that folder.inetmgr
in the text box and click OK. Right-click on the Web
site where you want to create a virtual directory, click New, and click Virtual
Directory. In the Alias text box, type the name you want for your virtual directory, for
example, AuthFilt
. In the Directory text box, type the path to the
folder that contains your files.
AuthFilt
in the
Filter Name text box, and type the path to your filter in the Executable text box.
Click OK to complete the installation of the filter.c:\inetsrv\userdb.txt
, which contains the username/password
pairs and the appropriate account the username/password should be mapped to. The format of the
file is:User1:Password1, NTUser1:NTPassword1Where each line contains the user name and password that will be used to authenticate the user, a comma, and the NT Username and password.
In order to run this sample, follow the instructions listed below:
AuthFilt
, type
http://localhost/AuthFilt/AuthFilt.htm
in the Address bar
of IE.
After performing step 1 in Run the Sample, you should be queried for authentication based on the data in the user file you created.
to top
If here you do not find answers to your questions, visit the Microsoft Help and Support Web site.
Problem | Possible Solution |
---|---|
When building the dll, C++ returns a permissions error. | Once you have called the dll from your web page, your system considers it a loaded dll. You must unload it to build it again, either by unloading the ASP application or deleting the dll from system32\dllcache. |
When browsing to the dll, IE gives you a permissions error. | The folder and virtual directory must have Execute permissions set on them. |
© 1997-2002 Microsoft Corporation. All rights reserved.