Get Server variables from within a COM

  • Thread starter Thread starter Usman
  • Start date Start date
U

Usman

Hi

I've a web application written in ASP.Net. I'm calling a COM component from
it. Is there any way I can get the Server variables or Session variables of
that web application from within this COM.

Regards

Usman
 
Usman said:
Hi

I've a web application written in ASP.Net. I'm calling a COM component
from
it. Is there any way I can get the Server variables or Session variables
of
that web application from within this COM.

Sure,

You need to set AspCompat="true" as page tag in your asp.net page.

Further on, you just implement the IObjectControl interface in your
component...


make this a member variable!
CComPtr<ISessionObject> m_piSession;


//Active implementation from IObjectControl

STDMETHOD yourclass:Activate()
{
hr = CoGetObjectContext(IID_IObjectContext, (void**)&m_piObjContext);

if (hr == S_OK)

{

CComQIPtr<IContextProperties> pProps(m_piObjContext);



CComVariant vitem;


hr = pProps->GetProperty(CComBSTR(L"Session"), &vitem);


if (hr == S_OK)

{

vitem.pdispVal->QueryInterface(&m_piSession);

vitem.Clear();

}

return hr;

}
Regards

Usman


Keep in mind that you cannot share .NET specific variables with a COM object
like the 'long' datatype, or .NET references to managed classes! The
limitation is existing because the classic ASP interop code simply has not
been written with .NET in mind.
 
Egbert Nierop (MVP for IIS) said:
Sure,

You need to set AspCompat="true" as page tag in your asp.net page.

Forgot to add that you need to register the component in a COM+ app. It can
be in-proc and don't be afraid that the performance (often made prejudice by
programmers) would suffer by COM+. Disable synchronization in that
component. It probably does not need extra wrappers for syncing since
ASP.NET already syncs.
 
Back
Top