Hosting .NET Windows Forms in IE .NET Windows Forms

xiaoxiao2021-03-06  43

In this step, we will create the HTML web page of the hostwork, the HTML web page, the code of the HTML page is as follows:

Authors Display Control



After creating an HTML page, we also need to create a virtual directory for hoster HTML web pages and controls. Once you have created a virtual directory, we can copy the HTML web pages and controls to the physical directory being mapped to the virtual directory. Now, we can test the control by browsing the HTML page. In the HTML web page, we will see a command control part of the Form Control. If you click the command button, it calls the web service from the browser on the client and displays the result of the web service in the DataGrid. The output of the HTML page is as follows:

Debug Windows Forms control

In order to debug the control, we need to complete the following steps:

· Open the browser and request to browse the HTML webpage you created above.

· Open Visual Studio.net, select "Tools" -> Debug Process from the menu, display the following dialog:

· In the Process dialog, select IExplore.exe, click the "Additional" button. When you click the "Additional" button, the dialog shown below will appear, which will remind you to select the type of program to be debugged. In this dialog box, make sure the "Public Language Runture" option in the list is selected.

· Click the "OK" button in the above dialog box to re-return to the Process Dialog, this time, we only need to click the "Close" button.

• Open User Control File AuthorsWebServiceClientControl.cs from Files -> "Open" -> File menu, and set breakpoints in the Click event of the Command button.

· Return to the browser and click the Command button, the program will automatically run to the breakpoints just set in the control, we can use the Visual Studio .NET to debug code.

Code Access Permissions and Windows Forms Controls are as discussed above, when the control is executed in IE, it uses the code access provided by the .NET runtime library. To understand how the Windows Forms control running in IE is coordinated with the code access security mechanism provided by the .NET runtime library, we add a few lines of code in the Authors Form Control and create a new event log source. After modification, the control LOAD event is as follows:

(! EventLog.SourceExists ( "TestSource")) private void AuthorsControl_Load (object sender, System.EventArgs e) {if EventLog.CreateEventSource ( "TestSource", "TestLog"); else {EventLog.DeleteEventSource ( "TestSource"); EventLog .CreateEventSource ("testsource", "testlog");}}} In the above line of code, we check if the EventLog source named testsource exists. If there is no existence, create one, otherwise we delete an existing event source Create a new event source. Maybe you have already thought that the implementation of such an operation requires higher permissions, and the control downloaded from the Internet should not have permission to perform this operation. In order to ensure this, we copy the output of the control to the virtual directory. After completing this, if you browse the HTML page with a control, we will see the following dialog box:

The above dialog is clearly indicated that the code in the control is subject to the limitations of the code access security mechanism in the .NET time running library.

summary

Before using Windows Forms in IE, we need to pay attention to its advantages and restrictions. Its main advantages are:

· The ability to dynamically enrich the user experience through the web.

· The client compiled code automatic buffer.

· Seamless integration with .NET code Access security mechanism, allow us to use .NET security model from the client

· The performance of Java Applets is better than the Java Applets.

Restrictions include:

· Require the client to install a Windows operating system.

· Only IE 6.0 provides support for such hosting methods

· Require the client to install .NET runtime library

· Requires the server side to install at least Windows 2000, IIS 5.0 or above software.

It is necessary to detect whether the client has this capability because it will be subject to the above limitations. For example, since the hosted form control in IE needs to be installed on the client, we can write the code that checks if the client is installed with .NET runtime library. We can do this by checking the value of the request.browser.clrversion property. If installed, the version number is returned, otherwise it will return 0.0.

in conclusion

In this article, we have learned how to host Windows Forms controls in IE and how to debug controls, we have learned how to use the .NET code access security mechanism to configure the operation of time controls in the browser.

Although this technology requires a specific platform, it is still a promising technology, especially considering that .NET Framework will become an organic component of future versions of WINDOWS.

转载请注明原文地址:https://www.9cbs.com/read-113445.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.045, SQL: 9