IGetContextProperties Interface
Archived content. No warranty is made as to technical accuracy. Content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The IGetContextProperties interface provides access to context object properties.
On This Page
Remarks
IGetContextProperties::Count Method
IGetContextProperties::EnumNames Method
IGetContextProperties::GetProperty Method
Remarks
The header file for the IGetContextProperties interface is mtx.h.
The IGetContextProperties interface exposes the following methods.
Method |
Description |
---|---|
|
|
Count |
Returns the number of properties associated with the context object. |
EnumNames |
Returns a reference to an enumerator that you can use to iterate through all the context object properties. |
GetProperty |
Returns a context object property. |
See Also
Context Objects
IGetContextProperties::Count Method
Returns the number of context object properties.
Provided By
IGetContextProperties HRESULT IGetContextProperties::Count (
long * plCount**);**
Parameters
plCount
[out] The number of properties.
Return Values
S_OK
A valid count is returned in the plCount parameter.
E_INVALIDARG
The valid count could not be returned.
Example
IGetContextProperties::EnumNames Method
Returns a reference to an enumerator that you can use to iterate through all the context object properties.
Provided By
IGetContextProperties HRESULT IGetContextProperties::EnumNames (
IEnumNames ** ppenum );
Parameters
ppenum
[out] A reference to the IEnumNames interface on a new enumerator object that you can use to iterate through all the context object properties.
Return Values
S_OK
A reference to the requested enumerator is returned in the ppenum parameter.
E_INVALIDARG
The requested enumerator could not be returned.
Remarks
You use the EnumNames method to obtain a reference to an enumerator object. The returned IEnumNames interface exposes several methods you can use to iterate through a list of BSTRs representing context object properties. Once you have a name, you can use the GetProperty method to obtain a reference to the context object property it represents. See the COM documentation for information on enumerators.
As with any COM object, you must release an enumerator object when you're finished using it.
Example
IGetContextProperties::GetProperty Method
Returns a context object property.
Provided By
IGetContextProperties HRESULT IGetContextProperties::GetProperty (
BSTR name
VARIANT * pProperty );
Parameters
name
[in] The name of the context object property to be retrieved.
Pproperty
[out] The returned pointer to the property.
Return Values
S_OK
The property was returned successfully.
S_FALSE
The property was not found.
E_INVALIDARG
The name parameter was invalid.
Remarks
You can use GetProperty to retrieve the following Microsoft Internet Information Server (IIS) intrinsic objects:
Request
Response
Server
Application
Session
For more information, see the IIS documentation.
To retrieve an IIS object, call QueryInterface using the VT_DISPATCH member of the returned VARIANT for the interface to the IIS object (for example IReponse for the Response object).
Note: Context properties are not available in MTS 1.0 server processes.
Example
Count, EnumNames, GetProperty Methods Example
#include "stdafx.h" #include <initguid.h> #include "asptlb.h" #include "mtx.h" HRESULT hr = NOERROR; // Get the context object CComPtr<IObjectContext> pObjectContext; hr = GetObjectContext(&pObjectContext); // Get the Response object CComVariant v; CComBSTR bstr(L"Response"); CComQIPtr<IGetContextProperties, &IID_IGetContextProperties> pProps(pObjectContext); hr = pProps->GetProperty(bstr, &v); CComPtr<IDispatch> pDisp; pDisp = V_DISPATCH(&v); CComQIPtr<IResponse, &IID_IResponse> pResponse(pDisp); // Print number of properties long lCount; hr = pProps->Count(&lCount); bstr = L"<p>Number of properties: "; CComBSTR bstrCount; VarBstrFromI4(lCount, 0, 0, &bstrCount); bstr.Append(bstrCount); bstr.Append(L"</p>"); v = bstr; hr = pResponse->Write(v); // Iterate over properties collection and print the // names of the properties CComPtr<IEnumNames> pEnum; CComBSTR bstrTemp; pProps->EnumNames(&pEnum); for ( int i = 0; i < lCount; ++i ) { pEnum->Next(1, &bstr, NULL); bstrTemp = L"<p>"; bstrTemp.Append(bstr); bstrTemp.Append(L"</p>"); v = bstrTemp; hr = pResponse->Write(v); }