Referencing and Executing DLL Code


Once you partition your code so that some of the code runs from a separate DLL, you will want to create instances of the classes in that DLL from your Web application. There are two ways to reference that DLL from a Web application.

To reference a DLL from a Web application:

  1. In a Web application project, right-click on the References item in the Solution Explorer window and select Add Reference.

  2. In the References dialog, click the Browse button. You will see the Select Component dialog. Find your DLL file ( Figure 13.6 ).

    Figure 13.6. Once you compile the DLL project from the previous section you can add a reference to it in your Web application. This makes the wizard copy the DLL to the application's bin directory. Whenever you build the Web project, the copy of the DLL is refreshed.

    graphics/13fig06.jpg

  3. Click OK to close the References dialog.

  4. When you run the application in a production environment (outside of VS.NET) copy the DLL to the bin subdirectory under your Web application's virtual directory. Chapter 2, "C# Building Blocks," explains how to set up a virtual directory for your Web application.

  5. Add the DLL to the Global Assembly Cache (GAC). The GAC ( Figure 13.7 ) is a special directory for DLLs that are to be shared among various applications. To add a DLL to the GAC you need to first digitally sign the DLL. For details, read the section "Making DLLs Globally Available" on the next page.

    Figure 13.7. Assembly heaven! This is where assemblies that have been protected against tampering reside. Every Web and Windows Forms application can share the same copy of the DLL if it is in the Assembly cache.

    graphics/13fig07.gif

graphics/tick.gif Tip

  • VS.NET takes all the code for your Web Form pages and turns it into a single DLL file. Your Web Form forms in .aspx files reference this DLL. VS.NET automatically creates a bin subdirectory under your Web application's directory and copies the main DLL there. You can also copy to the bin directory any other DLLs your application needs.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net