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;
}
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.