Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using a .NET UserControl as container for NI OCX's on an ASPX WebForm

I am evaluating MStudio with VS.NET and want to use a .NET UserControl as a container for NI OCX's for sharing code between Windows- and Web projects.

The control works fine on a WindowsForm, but not on a WebForm.

The UserControl is placed in an OBJECT Tag on my Webform like this:

<OBJECT id="UserControl1" style="WIDTH: 255px; HEIGHT: 172px" height="172" width="255" classid=http://localhost/WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1 VIEWASTEXT> </OBJECT>

This also works on a WebForm if I'm not using an OCX on the Control, but only "native" NET controls.

What am I missing???

Do I have to wait for the MStudio.NET edition???

Brgds JRemoy
0 Kudos
Message 1 of 7
(4,042 Views)
I haven't tried it, but if I had to guess I'd say that it doesn't work due to .NET code access security restrictions. More specifically, the Internet zone code group on the client does not have permission to execute unmanaged code, hence the client doesn't have permissions to run the controls that are contained in the user control.

Just out of curiosity, are you using a Windows Forms user control for any other reason than to contain ActiveX controls (for example, does it also contain any Windows Forms controls)? If not, I think it would be better to create a user control in VB6 since the Windows Forms user control would introduce an unnecessary dependency on the .NET Framework on the client. You could then digitally sign your ActiveX user control and th
e clients could specify that they trust the publisher to allow the controls to run. This would still allow you to use the user control in both Windows Forms and Web Forms since you could generate an interop wrapper control for the ActiveX user control for the Windows Forms case.

- Elton
Message 2 of 7
(4,042 Views)
Thanks for your reply.

I am planning to use new .NET technologies like Remoting in my UserControl. What I need in addition is a real time charting component, maybe a NI components?

I have downloaded the MStudio 7.0 .NET beta. Can I use the graph control there in the way I sketched in my last posting? I have tried, but with the same result as with an OCX. Isn�t this a �native� NET control like TextBox, Buttons, etc?

Brgds Jan
0 Kudos
Message 3 of 7
(4,042 Views)
Yes, the Windows Forms graph in the Measurement Studio 7.0 .NET beta is a native .NET control, but it does require certain code access security permissions to run, not all of which will be encompassed by the local intranet or internet code groups. I'm guessing that the problem you ran into when you tried this is either a.) your client did not have sufficient code access security permissions to run your user control, and/or b.) your virtual directory execution permissions were not configured correctly for proper control activation.

I tested creating a user control using the beta graph and here are the steps that I followed to get things working:


  1. Create the user control.

  2. Create a virtual directory on your web server to run your application from. Copy the assembly that contains your user control along with NationalInstruments.Common.dll, NationalInstruments.UI.dll, and NationalInstruments.UI.WindowsForms.dll to the virtual directory. Make sure that the execution permissions on the virtual directory are set to Scripts Only and not Scripts and Executables.

  3. Configure the code access security permissions on the client so that the client has the required permissions for the control to run. In this example, I did this by:

    • Go to Microsoft .NET Framework 1.1 Configuration in Administrative Tools.

    • In the .NET Configuration, go to Runtime Security Policy->Machine->Code Groups->All_Code->LocalIntranet_Zone. Right-click on LocalIntranet_Zone and click New...

    • Enter a name for your new code group and click Next.

    • Choose URL from the dropdown in the next dialog, then enter http://[servername]/* in the URL textbox where [servername] is your web server, then click Next.
    • Accept the default FullTrust permission set in the next dialog, click Next, then click Finish.



  4. Add an object tag to an HTML page in the virtual directory to activate the user control on the web page. This is done like this:


    <object classid="http:[assembly]#[control]" ...>


    Where [assembly] is the name of the assembly that contains your user control and [control] is the fully-qualified name of the user control. Note that this syntax is slightly different than your original post.


  5. Test it out in Internet Explorer. Note that you'll need to use the same server name that you specified in the .NET Framework Configuration. For example, if you entered your machine name and you're testing from your local machine, you'll need to enter your machine name and not localhost.



A couple of side notes - first, depending on if you're running your application on an intranet or the internet, your clients may not be comfortable with configuring FullTrust permission from anything that runs from your server. There are other things that you can do, such as determine the exact permissions that are required and configure those, or limit the URL in the code group to just your virtual directory. Also, I realize that the requirement of setting up code access security permissions on the client can be inconvenient, but this can be made easier by creating an installer that clients run once to automate the process. For more information on this, please see the MSDN article Increasing Permissions for Web-Deployed Windows Forms Applications.

Hopefully this helps. Please give this a shot and post a follow-up to tell us how things work out. Thanks.

- Elton
0 Kudos
Message 4 of 7
(4,042 Views)
A couple of more side notes - there is other evidence that you may want to consider using to configure your security policy, such as a strong name or a digital certificate. Also, instead of hosting your application in a web browser, you may want to consider deploying it at a smart client. For more information, see:



- Elton
0 Kudos
Message 5 of 7
(4,042 Views)
First, thanks for all your support. It has been very helpful.

Follow up:
I made a UserControl with a DataSocket and a WaveformGraph component, embedded it in a HTML Page as you described. This worked fine on local-machine but not over the Intranet. All referenced DLL�s were downloaded to the �Global Download cache� but plug-in would not run. Then I installed the full package of MStudio on the remote machine - that helped. Can you tell me why?

Conclusion:
Measurement Studio .NET would be great in our application, but I have to dig more into .NET security�

Brgds JanG

PS:
It also worked fine as a Smart Client -thanks for your tip. We will consider using this deployment method.
0 Kudos
Message 6 of 7
(4,042 Views)
The problem was probably because DataSocket was not on the machine. The Measurement Studio .NET UI controls are 100% managed components, but the Measurement Studio .NET DataSocket components are .NET interfaces to the unmanaged DataSocket API. So for the UI components you only need the .NET assemblies on the client machine, but for DataSocket you will need to have the DataSocket .dll installed and registered on the client machine in addition to the assembly.

- Elton
0 Kudos
Message 7 of 7
(4,042 Views)