all groups > asp.net building controls > october 2004 >
You're in the

asp.net building controls

group:

Non-visual C# objects on a webpage are not marked as "safe for scr


Non-visual C# objects on a webpage are not marked as "safe for scr lwickland
10/26/2004 8:11:04 AM
asp.net building controls:
Non-visual C# objects on a webpage are not marked as "safe for scripting"

I'm developing .NET components in C# which are used as ActiveX-style
controls on web pages that are displayed inside a custom browser which is
based on the IE web browser control. On 3 of about 100 PCs that the controls
have been tried on, the browser produces the following error message:

An ActiveX control on this page is not safe.
Your current security settings prohibit running unsafe controls on this
page.
As a result, this page may not display as intended.

I believe this is the "not safe for scripting" error. According to what
I've read, we shouldn't be seeing this error because the object tag which
puts the C# control on the page references a URL in the CLASSID attribute;
supposedly this type of reference automatically marks the object as safe for
scripting. However, neither adding a 'mayscript="true"' attribute to the
object tag nor implementing IObjectSafety eliminates the problem.

The problem only plagues non-visual controls, i.e., C# objects which do not
inherit from System.Windows.Forms.Control. The only step required to
alleviate the problem is to inherit from System.Windows.Forms.Control or one
of its derivatives. However, inheriting from System.ComponentModel.Component
does not eliminate the error message.

Is this the expected behavior? Is there another workaround which would
allow me to put non-visual, non-Control-derived C# classes on the web page?

I'm using v1.1 SP1 of the Framework.
RE: Non-visual C# objects on a webpage are not marked as "safe for scr lwickland
10/26/2004 10:43:06 AM
[quoted text, click to view]
Nicholas,

Thanks for replying.

As I noted in my original post, I have tried implementing IObjectSafety to
no avail.

I stuck MessageBox.Show()s in the methods implementing IObjectSafety to
ensure that I had implemented it correctly. On a PC that didn't display the
"safe for scripting" error, the MessageBox.Show()s were displayed as expected
when the javascript on the web page referenced the C# object. On a PC that
did display the "safe for scripting" error, the MessageBoxes weren't
displayed, indicating to me that the web page wasn't recognizing that the
object implemented IObjectSafety.

Do you have any further suggestions?

We haven't been able to find any pattern to the PCs that the problem has
appeared on; we've seen the issue on both Windows 2000 and Windows XP.

Thanks,

Leif Wickland
Re: Non-visual C# objects on a webpage are not marked as "safe for scr Nicholas Paldino [.NET/C# MVP]
10/26/2004 11:58:53 AM
lwickland,

I would try and define the IObjectSafety interface on your objects. You
would have to define it first, but that should be a trivial matter.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

[quoted text, click to view]

Re: Non-visual C# objects on a webpage are not marked as "safe for scr Robert Jordan
10/26/2004 8:06:55 PM
Hi,


[quoted text, click to view]

IObjectSafety & friends


/// <summary>
/// See Internet SDK, IObjectSafety.
/// </summary>
[Flags]
public enum ObjectSafetyFlags : int
{
/// <summary>
/// Caller of interface may be untrusted
/// </summary>
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 1,

/// <summary>
/// Data passed into interface may be untrusted
/// </summary>
INTERFACESAFE_FOR_UNTRUSTED_DATA = 2,

/// <summary>
/// Object knows to use IDispatchEx.
/// </summary>
INTERFACE_USES_DISPEX = 4,

/// <summary>
/// Objects knows to use IInternetHostSecurityManager.
/// </summary>
INTERFACE_USES_SECURITY_MANAGER = 8,

/// <summary>
/// Flags combination.
/// </summary>
SafeForScripting = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA
}

/// <summary>
/// See Internet SDK, IObjectSafety.
/// </summary>
[ComVisible(true)]
[ComImport]
[Guid("CB5BDC81-93C1-11cf-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
void GetInterfaceSafetyOptions(ref Guid riid, out int
supportedOptions, out int enabledOptions);
void SetInterfaceSafetyOptions(ref Guid riid, int
optionSetMask, int enabledOptions);
}



Implementation:


[ComVisible(true)]
[Guid("773ecc45-670f-45d0-8780-2ab71c654a21")]
public class MyUserControl : UserControl, IObjectSafety
{
...
public void GetInterfaceSafetyOptions(ref Guid riid, out int
supportedOptions, out int enabledOptions)
{
supportedOptions = enabledOptions = (int)
ObjectSafetyFlags.SafeForScripting;
}

public void SetInterfaceSafetyOptions(ref Guid riid, int
optionSetMask, int enabledOptions)
{
}
....
}


bye
Re: Non-visual C# objects on a webpage are not marked as &quot;safe for Robert Jordan
11/23/2004 10:44:36 AM

Hi,


[quoted text, click to view]


IObjectSafety & friends


/// <summary>
/// See Internet SDK, IObjectSafety.
/// </summary>
[Flags]
public enum ObjectSafetyFlags : int
{
/// <summary>
/// Caller of interface may be untrusted
/// </summary>
INTERFACESAFE_FOR_UNTRUSTED_CALLER = 1,

/// <summary>
/// Data passed into interface may be untrusted
/// </summary>
INTERFACESAFE_FOR_UNTRUSTED_DATA = 2,

/// <summary>
/// Object knows to use IDispatchEx.
/// </summary>
INTERFACE_USES_DISPEX = 4,

/// <summary>
/// Objects knows to use IInternetHostSecurityManager.
/// </summary>
INTERFACE_USES_SECURITY_MANAGER = 8,

/// <summary>
/// Flags combination.
/// </summary>
SafeForScripting = INTERFACESAFE_FOR_UNTRUSTED_CALLER |
INTERFACESAFE_FOR_UNTRUSTED_DATA
}

/// <summary>
/// See Internet SDK, IObjectSafety.
/// </summary>
[ComVisible(true)]
[ComImport]
[Guid("CB5BDC81-93C1-11cf-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
void GetInterfaceSafetyOptions(ref Guid riid, out int
supportedOptions, out int enabledOptions);
void SetInterfaceSafetyOptions(ref Guid riid, int
optionSetMask, int enabledOptions);
}



Implementation:


[ComVisible(true)]
[Guid("773ecc45-670f-45d0-8780-2ab71c654a21")]
public class MyUserControl : UserControl, IObjectSafety
{
...
public void GetInterfaceSafetyOptions(ref Guid riid, out int
supportedOptions, out int enabledOptions)
{
supportedOptions = enabledOptions = (int)
ObjectSafetyFlags.SafeForScripting;
}

public void SetInterfaceSafetyOptions(ref Guid riid, int
optionSetMask, int enabledOptions)
{
}
....
}


bye
Rob



---------------
Posted using Community Server NewsReader, Alpha
Re: Non-visual C# objects on a webpage are not marked as "safe for How to implement IObjectSafety with C#?
12/7/2004 2:35:39 PM
Hi,

Can someone show me how to implement the IObjectSafety (or any other MS
defined) interface using C#? I am new to .NET and apparently I am missing
something. Everything I've tried does not work.

Jeff Finz

[quoted text, click to view]
Re: Non-visual C# objects on a webpage are not marked as &quot;saf lwickland
12/7/2004 5:09:03 PM
[quoted text, click to view]

I tried implementing IObjectSafety as you've listed it here and I saw the
same "not safe for scripting" error. It's worth mentioning that my class
wasn't derived from Control or UserControl as yours was.

Thanks for the suggestion.
AddThis Social Bookmark Button