Re: Windows .NET forms - controls in IE?

From: Erick Lee (
Date: 07/27/03

Date: Sun, 27 Jul 2003 15:28:49 -0500

There are many articles on this however none of them really hit on the most
troublesome part of this process - security. Many gloss over it and give
you solutions that don't work. I have been working on two controls for a
week trying to make .NET 1.1 allow access via a Strong Name. However, this
will not work. You have to use URL or Site name to do anything other than
what you are given in the Internet Zone. Also the behavior of .NET change
between version 1.0 (sp1 & 2) and 1.1.

-- The following post helped shed some light.
How to run a user control assembly hosted on an Internet Information Server
(IIS) on an Internet Explorer (IE) client.

The following applies to an assembly intended to execute with greater
permissions than would normally be granted to the zone the assembly belongs
to, most likely Internet, Local Intranet or Trusted Sites.

1.. The user control assembly is identifiable in a manner that can be used
to set the membership condition in a code group either using the .NET
Configuration Tool (Mscorcfg.msc) or caspol.exe. Signing using a strong
name or a certificate is preferable, but other sources of identity such as a
URL or site can also be used. Although a URL or site can serve as a
membership condition, they are not recommended, as they are not as secure as
a strong name or a certificate.

To create a strong name use sn.exe:

sn -k keyPair.snk

// This strong name key is used to create a code group that gives //
permissions to this assembly.

// Sign the assembly with the strong name key.

[assembly: AssemblyKeyFile("keyPair.snk")]

2.. If strong named, the user control has the
AllowedPartiallyTrustedCallers attribute.

// The AllowPartiallyTrustedCallersAttribute requires the assembly to // be
signed with a strong name key.

// This attribute is necessary since the control is called by either an //
intranet or Internet Web page that should be running under //
restricted permissions.

// The fully attributed assembly should look similar to the following:

[assembly: AssemblyKeyFile("snKey.snk")]

[assembly: AssemblyVersion("")]


namespace SignedAssembly

3.. The user control asserts permissions it requires which the zone in
which it is running would not normally be granted. Permissions should only
be asserted if it is positively known the calling application has
insufficient permissions. Asserts should not be performed without a strong
new FileIOPermission(PermissionState.Unrestricted).Assert();

textBox1.Text = fileDialog.FileName;

// Display the contents of the file in the text box.

FileStream fsIn = new FileStream(textBox1.Text, FileMode.Open,
FileAccess.Read, FileShare.Read);

StreamReader sr = new StreamReader(fsIn);

// Process every line in the file

for (String Line = sr.ReadLine(); Line != null; Line = sr.ReadLine())




// It is very important to call RevertAssert to restore the stack walk //
for file operations.


4.. The user control RevertAsserts immediately after performing asserted
// It is very important to call RevertAssert to restore the stack walk //
for file operations.


5.. The user control is hosted in an IIS folder on the server that has an
"Execute permission" set to either "None" or "Scripts Only".

6.. The client has a code group that the assembly resolves to that grants
the permissions the assembly requires.
caspol -machine -addgroup All_Code -strong -file signedassembly.exe
FullTrust -name FouthCoffeeStrongName -description "Code group granting
trust to code signed by FourthCoffee"

Alternatively, the code group can be created using the Microsoft .NET
Framework Configuration tool (Mscorcfg.msc) found under Administrative

7.. In Internet Explorer, Internet Options, Advanced Security settings,
the "Do not save encrypted pages to disk" should be unchecked if Internet
Explorer Enhanced Security Configuration has been enabled for both
Administrators and for Other Groups on the server. The Internet Explorer
Enhanced Security setting selected is the default on Windows Server 2003.
When in effect, one of the invoked features is the encryption of downloaded
files. Another feature is the automatic setting of "Do not save encrypted
pages to disk" on the client. To successfully download a user control under
these conditions, the client setting for "Do not save encrypted pages to
disk" should be cleared. This functionality is found in Control Panel, Add
or Remove Programs, Add/Remove Windows Components, Internet Explorer
Enhanced Security Configuration.

8.. The runtime version on the client machine is compatible with the used
to compile the assembly.

9.. The code group created for the user control is in the same runtime
that the control uses.

If problems occur, check the Fusionbinderror log in "C:\Documents and
Settings\<username>\Local Settings\Temporary Internet Files" to determine
which operations failed. This log must first be copied to another folder
before it can be opened.

Lastly you asked can calls be made back to the server, yes. You have to rap
you control within COM(complicated) or use a web service(easier).

I have many URL which talk about creating a user control in IE. So if you
need more let me know.

"Dewayne Cushman" <dcushman at texas dot net> wrote in message
> I'm working on this right now, here is a decent starting point. A good
> search on Winforms IE will find others.
> Part of my problems are getting non-trivial programs to work. "Hello
> is fine, but trying more complicated controls are driving me nuts.
> Best of luck,
> Dewayne Cushman
> "Luther Miller" <luther.miller@softagondotcom.invalid> wrote in message
> news:Ojww%23zWTDHA.2460@TK2MSFTNGP10.phx.gbl...
> > I believe I have read somewhere that I can create a Windows Forms
> in
> > .NET (I am NOT talking about web controls / server controls /
> > and embed it in web page in Internet Explorer, making use of DHTML.
> >
> > Are there any good references / guides to this? I couldn't find anything
> in
> > the documentation. E.g., are there special interfaces the control needs
> > support? How does the control interact with Jscript? Can it fire events,
> > etc., and generally interact with the rest of the web page?
> >
> > Furthermore, what security restrictions are placed on the control? Are
> they
> > the same as a .NET exe executed from the browser? Can the control make
> > services calls back to the same server?
> >
> > Thanks in advance..
> >
> >

Relevant Pages