I keep getting this message “an activex control on this page might be unsafe to interact with other parts of the page. do you want to allow this interaction” when I try to access a page that use Javascript to access ActiveX Code. I’ve spent quite sometime to get rid of this error message and I found out that
- The code need implement IObjectSafety Interface
- You need to digitally sign the code with valid certificate
Step 1 : Detail on how to implement IObjectSafety
-Create an interface file called as IObjectSafety.vb/IObjectSafety.cs
CSharp (IObjectSafety.cs) :
[ComImport()] [Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IObjectSafety { [PreserveSig()] int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions); [PreserveSig()] int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions); }
Imports System.Runtime.InteropServices _ _ _ Interface IObjectSafety _ Function GetInterfaceSafetyOptions(ByRef riid As Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer _ Function SetInterfaceSafetyOptions(ByRef riid As Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer End Interface
in your ActiveX code you need to implement IObjectSafety
CSharp:
VB.NET:
_ _ _ _ Public NotInheritable Class ClientUtility Implements IObjectSafety #Region "IObjectSafety Constants" Private Const INTERFACESAFE_FOR_UNTRUSTED_CALLER As Integer = &H1 Private Const INTERFACESAFE_FOR_UNTRUSTED_DATA As Integer = &H2 Private Const S_OK As Integer = 0 #End Region #Region "IObjectSafety Methods" Public Function GetInterfaceSafetyOptions(ByRef riid As System.Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or INTERFACESAFE_FOR_UNTRUSTED_DATA Return S_OK End Function Public Function SetInterfaceSafetyOptions(ByRef riid As System.Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions Return S_OK End Function #End Region
CSharp:
[ProgId("Fransiscus.Authentication.ClientUtility")] [ClassInterface(ClassInterfaceType.AutoDual), ComSourceInterfaces("ControlEvents")] [Guid("0577147B-6941-4f15-9EFB-2551FEB3D6CC")] [ComVisible(true)] public sealed class ClientUtility : IObjectSafety { #region "IObjectSafety Constants" private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x1; private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x2; private const int S_OK = 0; #endregion #region "IObjectSafety Methods" public int GetInterfaceSafetyOptions(ref System.Guid riid, ref int pdwSupportedOptions, ref int pdwEnabledOptions) { pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; return S_OK; } public int SetInterfaceSafetyOptions(ref System.Guid riid, int dwOptionSetMask, int dwEnabledOptions) { return S_OK; } #endregion }
Step 2:
You need to obtain certificate and sign it, You also need Windows Server 2008 SDK to sign your code using SignTool.exe (type Signtool SignWizard in command prompt to follow the wizard and sign your DLL)
For more detail please open verisign website (http://www.verisign.com/support/code-signing-support/code-signing/identity-authentication.html) or click here
Leave a Reply