Use Windows Form Controls in IE Browser [Translation]

zhaozj2021-02-16  33

Use Windows Form Controls in IE Browser

Author: Thiru Thangarathinam

Translation: Zheng Zo

I. Introduction

In the past, web programmers often use ActiveX controls in their web programs to implement some fat clients. But now developers can easily create objects through Microsoft.NET Framework, and it is convenient to cut into use in the IE browser. Developers can realize a wealth web client by creating a Windows Form Control in the IE browser. In this article, we will know how to create a Windows Form Control and use it in IE. In the process of using the Form Control in your browser, we will demonstrate how to provide a rich web client display through a form control, and the form control is used to call remote Web Service to get data. At the same time, we will also know how to use the .NET security model to provide a safe operating environment for our form controls.

If you have experience in developing a web program with Java, you will be familiar with Java Applets. It is a small program running in the browser. Java Applets will run when the browser opens an HTML document containing an Applet tag. The WINDOWS form works in the WEB page. It is very similar to Java Applets. In this implementation, you create a form control and plus a rich Windows Form Control Style, followed by it. When the browser loads the web page, the code contained in the Windows control will be executed. This will be useful in a local area network or extended network program. For example, I want to develop a base with a web that has a fat client characteristic.

An important feature of .NET is to closely combine IE. For example, we can use Windows Form Controls in IE without notifying users to need additional things. This doesn't need to register anything .NET CLR will provide code security access capabilities.

When you create a Windows Form Control, you will have the features provided by the Form Class. For example, you can use the Windows Form Control Authentication technology to verify the accuracy of the input data. Similarly, you can even call Web Service in your form control. By using these technologies, you can create a rich, robust, dynamic application of the base with the .NET platform.

Remarks: According to the original text, replace the logging into Chinese, run the environment: operating system Windows 2003, .NET Framework 1.1. Here: Talking here: Open the browser in the debugging process to enter the full address. If the form control will not be displayed in a file mode; additional debugging of the process can be a single source file. However, I run the component generated under the debug version, not release, interested readers can try.

2. Execution

In this section, we will understand how to create a Windows Form Control and use it in IE. Five steps are listed below to complete this process.

1. Create a Windows Form Control 2. Create an HTML document with an Object tag that is used to identify the Windows Control 3. Configure the virtual path 4 of the control. Set the code access 5. Runput control

Let's take a look at the various steps above.

1. Create a Windows Form Control

In this step, we create a simple Windows Form Control. The function implemented by the control is to display "Hello World" to the user. Let's first create a Windows control library project named HelloWorldControl, modify the default user control for HelloWorldctl. Then add a Label to the control, named LBLDisplayMessage, and add a button BTNClick. When the user clicks the button, the following code will be executed to display the message to the user. Private void btnclick_click (Object Sender, System.EventArgs E)

{

this.lbldisplayMessage.Text = "Hello World";

}

Then it is to compile him to generate an assembly.

2. Create an HTML page

In this step, we will create an HTML document and insert the Object tab inside. The entire document looks as follows:

Hello World Control

In this label's classID property, we specify the path of the component created in the first step and the complete limit of the component. The entire full name includes namespaces and the entire class name. We can clearly see the component name and qualified name # segmentation in the code. These two partial parameters are combined together to identify the uniqueness of the control. Of course, you can write a client script by name the unique ID to HelloWorldControl1.

3. Configure virtual paths

With the HTML page, now create a virtual directory of HelloWorldControlHost, the actual directory in D: / My Programs / HellpWorldHost, which contains HelloWorldControl.dll and HellpWorld.htm files. When setting the virtual directory, you need to pay attention to setting the execution permission is "pure script". If set to "script and executable script" permissions. That control may not work properly (I am set to "script and executable script under IIS6", not normal). You can open the properties of the virtual directory to confirm the settings, set the window as follows:

4. Set code access

If this web is accessed in the local area network, he will work properly. If the web is accessed via the Internet, you need to set up Internet Explorer to modify security properties to allow him to run. You can join the home page to a trusted site. If you need to set the Tools menu of IE -> Internet Options -> Security -> Trusted site, click the site button to add your website to it. Next, when you open your browser, you will see it correctly.

5. Runput control

To run this control, we look at the HTML page that contains the control in the browser. If you click this button on the page, then the control will display "Hellp World", the execution page is as follows:

In this example, we implemented how to create a Windows Form Control and display it in the IE browser. In the next section, we have implemented access Web Service through the Form Control on the client browser.

III. An important advantage of accessing the Web Service Form Control through the Windows Form Control is that you can achieve extensive user information through it on the client. For example, you can access the web service through the Form Control to display in IE without re-refreshing the page. To demonstrate this, let's create a web service, then demonstrate how to call the Web service through the form control.

Create a web service

We created a Visual C # ASP.NET Web Service new project, named AuthorsWebService.

After establishing, we modify the service class name as AuthorsService, add a getauthors method in the class, the code of this method is as follows:

[WebMethod]

Public dataset getauthors ()

{

String connString = system.configuration.configurationSettings.Appsettings ["Connectionstring"];

SqlConnection SQLCONN = New SqlConnection (Conntring);

Dataset Dstauthors = New Dataset ("Authors");

SqlDataAdapter Adapter = New SqldataAdapter ("Select * from authors", SQLCONN);

Adapter.Fill (Dstauthors, "Author");

Sqlconn.close ();

Sqlconn.dispose ();

Return Dstauthi;

}

The code of the above method is relatively simple, we store the database connection string to the AppSettings node of the web.config file, as follows:



Now we need to create a virtual directory to make the control work normally and put authorsdisplay.htm and AuthorsWebServiceClientControl.dll. Open the browser to enter the address, you will see a button and an empty DataGrid, if you click the command button, the control will call the Web service while writing the result in the dataGrid. The page is shown below. In the next section, we look at the debugging of the process.

IV. Debugging Windows Form Controls

To adjust the form control, you need to follow the steps below.

1. Open the browser and request the HTML page containing the form control.

2. Open Visual Studio.NET Simultaneously Select Tools -> Debug Process Displays the following dialog box.

In this Process dialog box, select IExplore.exe Click the attach button. When you click on the additional button, you will jump out a dialog prompting you to select the type of programs you want to debug. We have chosen two items, as shown below:

Determine the top window and process window close.

Open User Control File AuthorsWebServiceClient.cs via the VS.NET file menu, set breakpoints in the source code. This once you set a breakpoint, you can debug this control, as shown below.

Windows Forms Code Access Permissions

Just like we have previously discussed. When the form control is executed in IE, he uses the permissions provided by the .NET runtime. To figure out how the control uses code access to the code provided by .NET to run in IE, let's go back in front, add the following code in the Form Control Load Event:

Private void authorscontrol_load (Object Sender, System.EventArgs E)

{

IF (! EventLog.Sourceexists ("testsource")))

EventLog.createEventSource ("Testsource", "Testlog"); ELSE

{

EventLog.DeleteEventsource ("testsource");

EventLog.createEventSource ("Testsource", "Testlog");

}

}

In the above code, we determine if there is a "TestLog" log source on the web server. If we do not exist, create him if we don't exist, if there is, delete the rebuild. Just like you expect, do more permissions, so the above code will not work properly through the Internet, you will see the following prompt window.

Through the above window we can clearly see your access is restricted by the .NET runtime.

When using the form control in IE, you need to realize his strengths and limitations. The main advantages include:

1. Implement a rich dynamic interface through web. 2. Seamlessly combined. NET code security strategy. 3. Preferably, the performance of Java Applets.

Restrictions include:

1. Client needs to be a Windows operating system

2. Need IE6.0 support

3. The client needs to install the .NET runtime environment

4. Server-side needs to be Window2000 and IIS5.0 or higher

Due to the above limit, it may be advantageous to transmit the client and server-side data. For example, because the WINDOWS Form Control is installed in the client IE, we can write some code to determine if the client is installed with .NET Runtime, we can get the version number through this feature, otherwise Will get 0.0.

V. conclusion

In this article, we discussed how to use browsing form controls in IE and debug in the process. At the same time, I also said that the .NET code accesses security control in IE.

Although the implementation of this technology requires client installation .Net runtime, we can believe that in the future Windows operating system will integrate .NET Framework, Windows2003 is a good example.

Finally, I hope that you will find this article to help you, thank you for reading.

About the Author

Thiru has almost six years of experience in architecting, designing, developing and implementing applications using Object Oriented Application development methodologies. He also possesses a thorough understanding of software life cycle (design, development and testing).

HE is an esp.net, .NET Framework, Visual C # .NET, Visual Basic.Net, ADO.NET, XML Web Services and .NET Remoting and Holds McAd for .NET, MCSD AND MCP CERTIFICATIONS.

Thiru Has Authored Numerous Books and Articles. He Can Be Reached At thiruthangarathinam@yahoo.com.

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

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