I'm working on a site (MVC) at the moment, which uses ajax quite heavily to request data from slow responding asynchronous resources.
I have a problem though, every request has to first be authorised, and part of that authorisation is to get the current RSA username, by doing Server.CreateObject("Rsacookieapi.RSACookie").GetUserName(). The problem is that this particular com object doesn't run on MTApartments, only STAparatments (they don't offer any alternative .net component, so we must use this one), therefore CreateObject fails.
I have got round this through much researching by creating a custom route handler that executes the controller context in an STA (equivalent to do ASPCOMPAT=TRUE on webforms), but this brings in a further problem, I can no longer create Asynchronous controller methods when the controller context is being executed from within an STA.
So I started thinking, if I could create the COM object in an STA, and somehow create a delegate/marshall to it, so it could be accessed from MTA, then all would be good.
As a proof of concept, I had a global variable myComObject, which I populated by doing the CreateObject from within an STA request (/StaController/Index).
I then tried to access myComObject from an MTA request (/MtaController/Index).
The great news is, this works. It appears as if the clr is handling all the marshalling for me.
So I began to write some code, that spawns a new thread in an STA, but the problem is i'm stil required to pass the HttpContext.Current.Server(HttpServerUtilityBase) to the thread, which when I call .CreateObject on just executes it on the MTA of the .Server object anyway.
I hope this makes sense? To clarify:
- I don't want any of my controllers or actions to be executed on an STA's
- I want to create the object on an STA's and then give access to it from all other MTA's
I sincerely hope someone has a suggestion!
Regards
Karl