I do not have experience in developing asp.net applications.
I want to develop an web application that uses a Componente COM with SxS registration-free.
Following this MSDN Article, Http Module I implemented an HttpModule
public class SyncModule : IHttpModule
{
private MyEventHandler _eventHandler = null;
public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(OnBeginRequest);
// Code that enable COM SxS registration-free
EnableSxSForThisThread_with_CreateActCtx();
int id = System.Threading.Thread.CurrentThread.ManagedThreadId;
Debug.WriteLine("MyModule Thread Id: " + id);
}
public void Dispose() { }
public delegate void MyEventHandler(Object s, EventArgs e);
public event MyEventHandler MyEvent
{
add { _eventHandler += value; }
remove { _eventHandler -= value; }
}
public void OnBeginRequest(Object s, EventArgs e)
{
HttpApplication app = s as HttpApplication;
int id = System.Threading.Thread.CurrentThread.ManagedThreadId;
Debug.WriteLine("OnBeginRequest Thread Id: " + id);
Debug.WriteLine("OnBeginRequest: Hello from OnBeginRequest in custom module.<br>");
if (_eventHandler != null)
_eventHandler(this, null);
}
Notice that Print Thread ID.
public void Init(HttpApplication app)
{
...
int id = System.Threading.Thread.CurrentThread.ManagedThreadId;
Debug.WriteLine("MyModule Thread Id: " + id);
}
And I linked with my web application putting this inside 'Web.confg'
<httpModules>
<add name="MyModule" type="MyModule.SyncModule, MyModule" />
</httpModules>
I run my web application and I can call the componente COM with sucess, but only for the same thread that runs HttpModule Init.
If I click at button to run again the thread that uses COM change and fail because HttpModule Init() was not called.
How to detected all new thread to call Init() and CreateActCtx correctly? Is it possible?