Solved

Hosting .NET UserControl in Internet Explorer

Posted on 2007-03-28
6
1,127 Views
Last Modified: 2013-11-07
Hello experts

I'm having a problem in hosting a .NET control within Internet Explorer.  I've followed numerous samples to the letter, and even downloaded example code.  I always seem to be hitting the same problem in that, where the .NET control should be, there is an image placeholder in its place.

I had previously had a text-box in it's place but, resolved that by changing the execution permissions to "Scripts Only" within IIS, as opposed to "Scripts and Executables".

The server where the page & control is hosted IS in the trusted sites, and I've tried it on a remote IIS server on the LAN, as well as running it from the local machine.  I've tried hosting the control in IIS on Windows XP, Windows 2000, as well as using IE6 from Windows 2000 / XP as a client.  All combinations give the same result.

Any advice as to what I'm doing wrong would be greatly appreciated.

Kind Regards

Daryl
0
Comment
Question by:hairyminga
6 Comments
 
LVL 8

Expert Comment

by:mppeters
ID: 18807438
I'm a little confused here. You don't really host a .NET user control. A user control (.ascx) is a custom control and can be used to plug a common set of elements in to a page. You use it almost the exact same way as you'd use a textbox, but since it's custom, it needs to be registered at the top of the page in the page directives.

What does the user control do? Can you post it here and how you're using it?

In theory, you could create a user control that just displays an image. So it's hard to diagnose what the problem is without more information.
0
 
LVL 3

Author Comment

by:hairyminga
ID: 18808109
Ah, sorry for the confusion.  I was meaning a WinForms control, not an ASP.NET user control.  It's similar functionality to ActiveX that I'm looking for.

I've created a WinNT service that connects to an ACD server in our call center (which doesn't normally offer very good realtime stats) and used the events raised from the server to create a true realtime statistics service.  I have client applications that are written in VB.NET that connect to the service and subscribe to these realitime statistics.  I'm hoping to get the same functionality from within a web page, so that I can have an ASP.NET information service that projects various details onto a collection of plasma screens around the building.

I've achieved something similar to this using an elaborate solution with an extra service on the IIS server, and AJAX but, I'd much rather code a WinForms control that will offer the statistics in realtime, and avoid having to introduce extra services, thereby creating extra points where the whole process can fall over.
0
 
LVL 3

Author Comment

by:hairyminga
ID: 18808362
And, to give you an idea of what I've attempted:

Within VS.NET (although I'm actually using #Develop), create a new User Control project in VB.NET, calling the project "HelloWorldControl" with one user control, called HelloWorldCtl

Here's the code for HelloWorldCtl:

Public Class HelloWorldCtl
      Inherits System.Windows.Forms.UserControl
      
      Public Sub New()
            ' The Me.InitializeComponent call is required for Windows Forms designer support.
            Me.InitializeComponent()
            
            '
            ' TODO : Add constructor code after InitializeComponents
            '
      End Sub
      
      Sub CmdClickClick(ByVal sender As Object, ByVal e As EventArgs)
            lblMessage.Text = "Hello, World"
      End Sub
      
      #Region " Designer Generated Code "
      
      Private components As System.ComponentModel.IContainer

      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                  If components IsNot Nothing Then
                        components.Dispose()
                  End If
            End If
            MyBase.Dispose(disposing)
      End Sub
      
      Private Sub InitializeComponent()
            Me.lblMessage = New System.Windows.Forms.Label
            Me.cmdClick = New System.Windows.Forms.Button
            Me.SuspendLayout
            '
            'lblMessage
            '
            Me.lblMessage.Location = New System.Drawing.Point(8, 8)
            Me.lblMessage.Name = "lblMessage"
            Me.lblMessage.Size = New System.Drawing.Size(224, 23)
            Me.lblMessage.TabIndex = 0
            Me.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            '
            'cmdClick
            '
            Me.cmdClick.Location = New System.Drawing.Point(8, 32)
            Me.cmdClick.Name = "cmdClick"
            Me.cmdClick.Size = New System.Drawing.Size(224, 23)
            Me.cmdClick.TabIndex = 1
            Me.cmdClick.Text = "Click Me"
            Me.cmdClick.UseVisualStyleBackColor = true
            AddHandler Me.cmdClick.Click, AddressOf Me.CmdClickClick
            '
            'HelloWorldCtl
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.Controls.Add(Me.cmdClick)
            Me.Controls.Add(Me.lblMessage)
            Me.Name = "HelloWorldCtl"
            Me.Size = New System.Drawing.Size(242, 65)
            Me.ResumeLayout(false)
      End Sub
      Private cmdClick As System.Windows.Forms.Button
      Private lblMessage As System.Windows.Forms.Label

      #End Region

End Class

The code compiles fine, and works when used in a .NET WinForms application.  Clicking the button places the text "Hello, World" into the label as expected.

I've created a virtual directory in an IIS 5.0 & IIS 6.0 server, called "HelloWorldControlHost" and, set the execution permissions to "Scripts Only" (as advised in various tutorials).  I've placed the resultant DLL from the above code (HelloWorldControl.dll) into the directory that holds the virtual path "HelloWorldControlHost", as well as placed "hello.html" (with the HTML code below).  When browsing the server with http://<server address>/HelloWorldControlHost.html i get the correct page, with no control.  Instead there's a placeholder there like as though Internet Explorer was trying to load an image file (jpg, gif etc).  If I change the execute permissions to "Scripts and Executables" then the same page gives me a textbox instead of the control, as warned in the tutorials.

Not sure if there's something I've misconfigured but, as stated, I've followed numerous tutorials to the letter, with no joy!

HTML Code from hello.html:

<html>
<body>
<p>Hello World Control<br> <br>
<object id="HelloWorldControl1" classid="http:HelloWorldControl.dll#HelloWorldControl.HelloWorldCtl" height="500" width="500" VIEWASTEXT>
</object>
</body>
</html>
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Accepted Solution

by:
bobbyrellis earned 500 total points
ID: 18996051
I see that you've read through many tutorials... but I don't see anything stating that you've setup a .NET code access group policy..

You need to set these security settings so IE knows where it can execute .NET code from a remote location safely..

Check this out..
http://msdn.microsoft.com/msdnmag/issues/02/06/rich/

Try this..
Go to the .NET configurations wizard  (Should be in administrative tools)
expand My Computer/Runtime Security Policy/Machine/Code Groups/All_Code. Right click/New and create a new Code Group with the following properties:
Name: HelloWorldControl
Condition Type: URL
URL= http://localhost/*
Permission set: FullTrust

This should give you permission to use your control.  Please let me know if you've tried anything similar to this.

Hope it helps.
0
 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 21073645
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
"Accept bobbyrellis's comment as answer."

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

zephyr_hex Experts Exchange Cleanup Volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21101997
Forced accept.

Computer101
EE Admin
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question