Code Sharing Model in AVS
Code Sharing Model in AVS
NET
Code sharing is a mechanism with which common code is shared among different pages of
your web application. It is important or beneficial when you want to make the code, with
specific functionality, accessible to all the web application. There are three methods are used
for code sharing model.
ASP.NET provides a unique directory known as the App_Code to store the code files that are
accessible to all the web pages of an application. When you add something in App_Code
folder, such as class or .wsdl files, it is automatically detected and compiled. Once compiled,
any page in your application can access them.
You can store source code in the App_Code folder, and it will be automatically compiled at run
time. The resulting assembly is accessible to any other code in the Web application. The
App_Code folder therefore works much like the Bin folder, except that you can store source
code in it instead of compiled code. The App_Code folder and its special status in an ASP.NET
Web application makes it possible to create custom classes and other source-code-only files
and use them in your Web application without having to compile them independently.
The App_Code folder can contain source code files written as traditional class files — that is,
files with a .vb extension, .cs extension, and so on. However, it can also include files that are
not explicitly in a specific programming language. Examples include .wsdl (Web service
description language) files and XML schema (.xsd) files. ASP.NET can compile these files into
assemblies.
Bin Directory
You can store compiled assemblies in the Bin folder, and other code anywhere in the Web
application (such as code for pages) automatically references it. A typical example is that you
have the compiled code for a custom class. You can copy the compiled assembly to the Bin
folder of your Web application and the class is then available to all pages.
Assemblies in the Bin folder do not need to be registered. The presence of a .dll file in the Bin
folder is sufficient for ASP.NET to recognize it. If you change the .dll and write a new version
of it to the Bin folder, ASP.NET detects the update and uses the new version of the .dll for new
page requests from then on.
Right click the URL in the Solution Explorer and add App-Code directory
Imports Microsoft.VisualBasic
Return a + b
End Function
End Class
Now you can access this code in your entire web application
Inherits System.Web.UI.Page
' access common code from App_Code folder using sum() function
End Sub
End Class
Each computer on which the Common Language Runtime is installed has a machine-wide code
cache called the 'Global Assembly Cache'. GAC is a folder in Windows directory to store the
.NET assemblies that are specifically designated to be shared by all applications executed on a
system. Assemblies can be shared among multiple applications on the machine by registering
them in global Assembly cache(GAC).
The GAC is automatically installed with the .NET runtime. The global assembly cache is located
in 'Windows/WinNT' directory and inherits the directory's access control list that administrators
have used to protect the folder.