Previous in Contents Next in Contents

Configuring the AUO

The following code examples demonstrate how to view and configure the Active User Objects (AUO) system for a new Membership Server instance. In this case, the default AUO provider is configured.  An ASP example also demonstrates simply listing the AUO configuration for the instance.

Examples are given in the following languages:

C++

C++ Using the #import directive

VBScript with the Windows Scripting Host

VBScript and ASP

C++ Example

This example demonstrates the process of creating and using the AuoConfig coclass in a C++ program. This class and associated COM interfaces are defined within the IDL file auo.idl.

Create the project directory for the C++ source code. The header files and GUID definitions are required, so we run the MIDL compiler on an appropriate interface definition language (IDL) file. You can either copy the file auo.idl from the \include directory of the SDK into the project directory, or use the OleView.exe application to bind to the type library and list the IDL definition. In the latter case, simply bind to the type library, which is located within the dynamic-link library c:\microsoft site server\bin\p&m\auo.dll. After it is bound, click the type library node in the tree. Select all the IDL text in the right pane and paste it into your favorite text editor. Save the text into a file named auo.idl. We now run the MIDL compiler with this file as the argument. This generates the necessary files:

auo.h

auo_i.c

auo.tlb

If you run MIDL on the auo.idl file that accompanies the SDK, two other files are generated:

auo_p.c

dlldata.c

These files are used to build a proxy dynamic-link library that can be used to marshal data to and from an instance of the object. Since the desired interfaces are marked with the dual attribute, the oleautomation attribute is implied. Thus, the Automation library can handle all marshalling duties using the type library within the AUO.DLL, and these files can therefore be ignored and/or discarded.

#include <stdio.h>
#include <auo.h>
#include <auo_i.c>
#include <iads.h>
main()
{
IObjCreator* pIObjCreator = 0;
IDispatch* pIDisp = 0;
IAuoConfig* pIAuoConfig = 0;
BSTR bszProgID = SysAllocString(L”MemAdmin.AuoConfig.1”);
BSTR bszServer = SysAllocString(L””);  // localhost

HRESULT hr = S_OK;
hr = CoCreateInstance(   CLSID_ObjCreator,
                           NULL,
                           CLSCTX_SERVER,
                           IID_IObjCreator,
                           (void**)&pIObjCreator);

if(FAILED(hr)) { ... }  // deal with error here

   // Get the IDispatch interface on the AuoConfig object 
hr = pIObjCreator->CreateObjAuth(bszProgID,bszServer,(void**)&pIDisp);
   
if(FAILED(hr)) { ... }  // deal with error here

// Fetch the IAuoConfig interface
hr = pIDisp->QueryInterface(IID_IAuoConfig,(void**)&pIAuoConfig);

if(FAILED(hr)) { ... }  // deal with error here

LONG Instance = 3;  // configure Membership Server 3
hr = pIAuoConfig->GetInfo(Instance);

BSTR name = SysAllocString(L"");  // default provider is empty string
BSTR AdsPathPrefix = SysAllocString(L"LDAP://server/o=realm/ou=members");
BSTR Schema = SysAllocString(L"LDAP://server/o=realm/ou=admin/cn=schema/cn=member");
BSTR Class = SysAllocString(L"member");
LONG Suffix = 1;
BSTR DepObj = SysAllocString(L"");
BSTR DepProp = SysAllocString(L"");
BSTR BindAsName = SysAllocString(L"");
BSTR BindAsPassword = SysAllocString(L"");
hr = pIAuoConfig->SetEntry(
                           Name,
                           AdsPathPrefix,
                           Schema,
                           Class,
                           Suffix,
                           DepObj,
                           DepProp,
                           BindAsName,
                           BindAsPassword );

// do the same for the named provider
// (code omitted)

hr = pIAuoConfig->SetInfo();
   
return 1;
}
   

}

Example Using the #import Directive

#include <iostream.h>
#import “c:\\Winnt\\System32\\objcreator.dll” no_namespace
#import “c:\\Microsoft Site Server\\bin\\P&M\auo.dll” no_namespace
main()
{
 CoInitialize(NULL);
 _bstr_t ProgID = “MemAdmin.AuoConfig”;
 _bstr_t Server = “”;
IObjCreatorPtr Creator = new IObjCreatorPtr(_uuidof(ObjCreator));

try 
{
   IAuoConfigPtr AuoConfig = Creator->CreateObjAuth(ProgID,Server);
}
 catch( _com_error Err )
 {
   cout << “Exception caught when trying to create AuoConfig” << endl;
   cout << “Description: “ << Err.Description() << endl; 
   cout << “HRESULT value: “ << Err.Error() << endl;
   cout << “Error Source: “ << Err.Source() << endl;
   exit(0);
 }
LONG Instance = 3;  // configure Membership Server 3
pIAuoConfig->GetInfo(Instance);

_bstr_t name = "";  // default provider is empty string
BSTR AdsPathPrefix = "LDAP://server/o=realm/ou=members";
BSTR Schema = "LDAP://server/o=realm/ou=admin/cn=schema/cn=member";
BSTR Class = "member";
LONG Suffix = 1;
BSTR DepObj = "";
BSTR DepProp = "";
BSTR BindAsName = "";
BSTR BindAsPassword = "";
try 
{
   pIAuoConfig->SetEntry(
                        Name,
                        AdsPathPrefix,
                        Schema,
                        Class,
                        Suffix,
                        DepObj,
                        DepProp,
                        BindAsName,
                        BindAsPassword );
}
catch (_com_error e ) 
{
  cout << "error calling SetEntry method on AuoConfig object" << endl;
  //...
}
// do the same for the named provider
// (code omitted)

try { pIAuoConfig->SetInfo(); }
catch { _com_error e ) {}
   

Scripting Languages Example

VBScript and Windows Scripting Host

The following code demonstrates a standard configuration for the AUO system. The important methods are in bold text.

Set IObjCreator = CreateObject("ObjCreator.ObjCreator.1")
Set IAuoConfig = IObjCreator.CreateObjAuth("MemAdmin.AuoConfig")

'  configure Membership virtual server that is mapped to IIS virtual server 3
Set IBrokServers = IObjCreator.CreateObjAuth("MemAdmin.BrokServers")
call IBrokServers.MappedTo("W3SVC",3,MemId,MemComment)

'  MemId now has the Membership virtual server instance ID
wscript.echo "Configuring Membership Server named: " & MemComment

IBrokServers = Nothing '  release interface ref
IAuoConfig.GetInfo(MemId)

Name = "LDAP2"
AdsPathPrefix = "LDAP://server:1000/o=company/ou=members"
Class = "member"
Schema = "LDAP://server:1000/o=company/ou=admin/cn=schema/cn=member"
Suffix = 1 '  registered user names used for this instance
' this is the DN of the directory user and password to use when binding
' to all ADSI objects from this DS.  
BindAsName = "o=company/ou=membersh/cn=administrator"
BindAsPassword = "password"

Call IAuoConfig.SetEntry(Name,
                     AdsPathPrefix,
                     Class,
                     Schema,
                     Suffix,
                     "",   ' DepObject; not used here
                     "",   ' DepProp;  not used here
                     BindAsUsername,
                     BindAsPassword )
IAuoConfig.SetInfo
Set IAuoConfig = Nothing   ' release interface ref

The following ASP example lists the Names (aliases) and Namespaces (providers) for the AUO for a given Membership server instance.

ASP and VBScript

<%
Set IObjCreator = Server.CreateObject("ObjCreator.ObjCreator.1")
Set IAuoConfig = IObjCreator.CreateObjAuth("MemAdmin.AuoConfig")

'  configure Membership virtual server that is mapped to IIS virtual server 3
Set IBrokServers = IObjCreator.CreateObjAuth("MemAdmin.BrokServers")
call IBrokServers.MappedTo("W3SVC",3,MemId,MemComment)

IAuoConfig.GetInfo MemId
IAuoConfig.GetEntries names,namespaces

Response.Write "The AUO entries for Membership Server " & MemId & "<br>"
Response.Write "Server Name: " & MemComment & "<br><br>"

For I = LBound(names) to UBound(names)
  if names(I) = "" Then
   names(I) = "Default"
  end if
  Response.write "Name: " & names(I) & "<br>"
  Response.write "Namespace: " & namespaces(I) & "<br><br>"
Next
%>

© 1997-2000 Microsoft Corporation. All rights reserved.