|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Criando os exemplos de controle de servidor personalizado
To create and compile the custom controls into an assembly
Create a folder for the source files for custom controls and related classes. Create a text file with the appropriate language extension for each example that you want to compile. For example, create a file named MailLink.cs for the C# code of the MailLink control in Exemplo de processamento de controle Web. Copy and paste the source code for each example into the corresponding text file and save the file. Run the following command from the source code folder to compile the controls and related classes into an assembly. csc /t:library /out:Samples.AspNet.CS.Controls.dll /r:System.dll /r:System.Web.dll /r:System.Design.dll *.csvbc /t:library /out:Samples.AspNet.VB.Controls.dll /r:System.dll /r:System.Web.dll /r:System.Design.dll *.vb
The /t:library compiler option tells the compiler to create a library (rather than an executable assembly). The /out option provides a name for the assembly and the /r option lists the assemblies that are linked to your assembly.
ObservaçãoIf you cannot execute the compiler command, you must add the .NET Framework installation path to the Windows PATH variable before running the command. In Windows, right-click My Computer, click Properties, click the Advanced tab, and then click the Environment Variables button. In the System variables list, double-click the Path variable. In the Variable value text box, add a semicolon (;) to the end of the existing values in the text box, and then type the path of your .NET Framework installation. The .NET Framework is usually installed in the Windows installation folder at \Microsoft.NET\Framework\versionNumber. Re-run the compilation command in Step 4 whenever you add new source files to the source code folder or change existing ones.
To create the ASP.NET Web site
Create an ASP.NET Web site using Internet Information Services (IIS) or another tool. For information about creating and configuring an IIS virtual directory, see Como: Criar e configurar diretórios virtuais no IIS 5.0 e 6.0.
ObservaçãoIf you want to use IIS, install IIS before installing the .NET Framework. Create a Bin folder under the root folder of your Web site. Copy the assembly you created in the preceding procedure to the Web site's Bin folder.
ObservaçãoIf you recompile the control assembly (the final step in the previous section) you must recopy the new assembly to the Bin folder of your Web site. Create a text file named Web.config in the root folder of your Web site, add the following XML to the Web.config file, and then save the file. <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true"/> <pages> <controls> <add tagPrefix="aspSample" namespace="Samples.AspNet.CS.Controls" assembly="Samples.AspNet.CS.Controls" > </add> </controls> </pages> </system.web> </configuration>
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true"/> <pages> <controls> <add tagPrefix="aspSample" namespace="Samples.AspNet.VB.Controls" assembly="Samples.AspNet.VB.Controls" > </add> </controls> </pages> </system.web> </configuration>
Add a text file with an .aspx extension to the root folder of your Web site for each example that you want to test. For example, create a file named MailLinkTest.aspx for the test page of the MailLink control provided in Exemplo de processamento de controle Web. Copy and paste the source code for each example test page into the corresponding .aspx file and save the file. Request the .aspx pages in a Web browser. For example, if your Web site is named ServerControls and it includes a page named MailLinkTest.aspx, type the following URL in the address bar of your browser: http://localhost/ServerControls/MailLinkTest.aspx
To put controls in the App_Code folder
Create an App_Code folder under the root folder of your Web site. Copy the source files for the controls and related classes into the App_Code folder. If you previously added an assembly for the control to the Bin folder, delete it.
ObservaçãoYou can either pre-compile a control into an assembly and place the assembly in the Bin folder or place the control's source file in the App_Code folder. If you add the control to both folders, the page parser will not be able to resolve a reference to the control in a page and will generate an error. Change the entry under the controls section in the Web.config file to the following highlighted entry, which maps the control's namespace to a tag prefix: <controls> <add tagPrefix="aspSample" namespace="Samples.AspNet.CS.Controls"> ..</add> </controls>
<controls> <add tagPrefix="aspSample" namespace="Samples.AspNet.VB.Controls"> ..</add> </controls>
For more information, see @ Register. Request the .aspx pages in a Web browser.
gacutil /l System.Design
Observação |
|---|
<compilation >
<assemblies>
<add assembly="System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Observação |
|---|