ActiveX control written in C# works locally but not when hosted by Apache

A

Andreas Schuler

Hi all,

I have written a UserControl derived object in C# and registered it as
a COM object using the Setup Project in VS 2005.

First questions are: is this the right way to go about COM with .NET? I
know about the GAC, do I still have to register the COM object in the
registry if I install my dll there (the Setup project allows me to put
my dlls in there)? Won't people installing my tool require
administrative privileges if I use the GAC (which I would consider a
drawback)? How would I refer to the object if it is in the GAC, still
via the GUID (see HTML code below)?

Now to the main issue I am facing:

I have written a very simple test page to test my control:

<html>
<head>
<title>Test Page</title>
</head>
<body>

<!-- using the object tag to call my ActiveX -->
<object id="nmp" name="nmp"
classid="clsid:afe80b5b-170e-467a-abdb-bc2394cf5429"
width="500" height="300">
</object>
<script>
function nmp::ErrorEvent(e)
{
alert('NMP reports an error: ' + e.Message);
var o = document.getElementById('nmp');
o.SetStream('00000000000000000000000000000000');
}
</script>
</body>
</html>


Now when I open this file from my computer with IE7 everything works
perfectly. But when I use my local Apache server to host this file, the
object doesn't show up! The really strange thing is that even when I
view the source within the browser it is letter for letter identical.

Has anyone experienced a similar problem? I am using version 2.0.59 of
Apache btw. Is there something wrong with the encoding? Even though I
doubt it, but is there any way Apache could somehow disable ActiveX
objects? Am a missing a security setting (although I did enable all
ActiveX related settings)?


Thanks for any suggestions in advance,

Andreas
 
A

Andreas Schuler

Hey all,

After a lot of researching I have found the root cause: my ActiveX
control was not marked as safe for scripting. I have no idea why this
would work when executed from a local html file as opposed to a hosted
one, but anyway. The solution is pretty simple and involved
implementing an additional interface called IObjectSafety.

The interface is not available in .NET but you can define it yourself.
See the following links for instructions how to do this:

http://blogs.msdn.com/infopath/archive/2005/04/15/408728.aspx
http://thegreenbutton.com/forums/thread/40951.aspx


I know there is another solution, which involves adding two special
keys to the registry, but I find this solution more elegant and easier
to implement.

I figured I'd share this with everyone because figuring this out took
me a while and the solution wasn't exactly obvious for a newbie ActiveX
developer :)

Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top