UserControl hosted in IE and Control.Invoke

  • Thread starter Remigiusz Samosiuk
  • Start date
R

Remigiusz Samosiuk

Hi everyone!!


I have such weird situation/bug I don't know how to solve

2 weeks ago I've done user control that is hosted in Internet Explorer.
This control in Load event starts backgroundworker
(http://weblogs.asp.net/rosherove/articles/BackgroundWorker.aspx) to
load some data from web service, and shows progress in progress bar.

Everything works great in default Internet Zone permission set, so now I
started to do another control to do similiar things.

But hey what's going on !!!
Background Worker seems to not working. So I had checked why, and found
that it has problem when it calls Control.Invoke method. It takes
SecurityException every time it will call it.

So I use reflector to find why, and found such lines of code in
Control.MarshaledInvoke method:

Control.ActiveXImpl impl1 = (Control.ActiveXImpl)
this.Properties.GetObject(Control.PropActiveXImpl);
if (impl1 != null)
{
IntSecurity.UnmanagedCode.Demand();
}

So my first suspicion was that for my first control I have set some
greater rights, but not, I have checked it on different computers and
found nothing - it works on client computers now without any additional
settings.

Later I've checekd - after debugging session with dissasembly window -
that for my first control Properties.GetObject(Control.PropActiveXImpl)
returns null, but for all other not.

Next thing I tried, was to create new UserControls but all have had the
same effect. Only the first one is working correctly.

Why, the first one control don't have this property set (but in debugger
I saw that it has ActiveXInstance property set)? I doesn't set anything
special on it. It was not so long ago, so I should remeber such special
settings.

What is my problem exactly?
1) Is Control.Invoke not premited for user controls hosted in IE and for
some reason one of my controls workarounds it?

OR

2) It should work, but I do something wrong?


Anyone ??

Thanks in advance
Remi
 
D

Dmytro Lapshyn [MVP]

Hi,

What I can think of is: Your first control is somehow marked as COM-visible
(with the ComVisible attribute, for example), and IE therefore thinks it's
an ActiveX control and do not apply any restricted permission sets. Now,
with all the other controls, they are recognized as .NET user controls and
run in the restricted "sandbox".
 
R

Remigiusz Samosiuk

Thanks for replay.

As for my knowledge all controls hosted in IE must have COMVisible attribute
set to true - which is by the way default behaviour. But maybe this is a
good search direction.

If it will not start to work, I will be forced to create some
detection/setup mechanism for permissions on client side. But I (my boss
exactly) realy don't wan't to do it. So I'm a little desperate

Thanks anyway
Remi
 
D

Dmytro Lapshyn [MVP]

Remigiusz,
As for my knowledge all controls hosted in IE must have COMVisible
attribute set to true - which is by the way default behaviour. But maybe
this is a good search direction.

No, Windows Forms User Controls hosted in IE do not need to have this
attribute at all - IE 6 is aware of .NET Framework and is able to host such
controls properly given the corresponding HTML tag instructs it it is a .NET
control, not an ActiveX one.

As for detecting permissions, .NET UserControls are given very restricted
set of permissions when hosted in IE. This is by design. You can possibly
override this by strong-naming the assembly containing the control and
creating a custom permission set on the client machine, but I am actually
not sure it works in such a scenario :-[
 

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