Solved

Hosting .NET UserControl in Internet Explorer

Posted on 2007-03-28
6
1,119 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 42

Expert Comment

by:zephyr_hex
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now