ASP.NET Tutorial/ASP.Net Instroduction/Directory Structure

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Application Directory Structure

   <source lang="csharp">

ASP.NET defines a few directories with special meanings.

Directory Description Bin Contains all the precompiled .NET assemblies usually DLLs

App_Code Contains source code files that are dynamically compiled for use

App_GlobalResources stores global resources App_LocalResources resources are accessible for their dedicated page only App_WebReferences Stores references to web services that the web application uses.

                   This includes WSDL files and discovery documents. 
                   

App_Data reserved for data storage

App_Browsers browser definitions stored in XML files

App_Themes themes used by the web application</source>


ASP.NET Application Folders

   <source lang="csharp">

\App_Code Folder stores your classes, .wsdl files, and typed datasets. Items in this folder are automatically available to all the pages within your solution. Because all the classes contained in this folder are built into a single assembly, you cannot have classes of different languages sitting in the root \App_Code folder \App_Code

   Calculator.cs
   AdvancedMath.vb

In order to work with multiple languages in your \App_Code folder, you must make some changes to the folder structure and to the web.config file. The first step is to add two new subfolders to the \App_Code folder - a \VB folder and a \CS folder. \App_Code

   \VB
       Add.vb
   \CS
       Subtract.cs

Structuring the web.config file <compilation>

  <codeSubDirectories>
     <add directoryName="VB"></add>
     <add directoryName="CS"></add>
  </codeSubDirectories>

</compilation></source>


ASP.NET Page Directives

   <source lang="csharp">

You can control the behavior of your ASP.NET pages by using these directives. Here"s an example of the Page directive: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"

   Inherits="_Default" %>

Directives are commands that the compiler uses when the page is compiled. Directives are simple to incorporate into your pages. A directive is written in the following format: <%@ [Directive] [Attribute=Value] %> You can add more than a single attribute to your directive statements: <%@ [Directive] [Attribute=Value] [Attribute=Value] %></source>


directives in ASP.NET

   <source lang="csharp">

Directive Description Assembly Links an assembly to the Page or user control for which it is associated. Control For using with user controls (.ascx). Implements Implements a specified .NET Framework interface. Import Imports namespaces into the Page or user control. Master Set master page. It be used only with master pages (.master). MasterType Associates a class name to a Page in order to get at strongly typed references. OutputCache Controls the output caching policies of a Page or user control. Page Enables you to specify page specific attributes and values to use when the page parses or compiles. PreviousPageType Enables an ASP.NET page to work with a postback from another page in the application. Reference Links a Page or user control to the current Page or user control. Register Associates aliases with namespaces and class names for notation in custom server control syntax.</source>


@Page directive

   <source lang="csharp">

@Page directive sets attributes and values for an ASP.NET page (.aspx). <%@ Page Language="VB"

        AutoEventWireup="false" 
        CodeFile="Default.aspx.vb"
        Inherits="_Default" %></source>
   
  

Page Directives, code section and layout

   <source lang="csharp">

<%@ Page Language="C#" %>

<script runat="server"> private void MakeUpper(object sender, EventArgs e) {

   string buf = TheString.Value;
   TheResult.InnerHtml = buf.ToUpper();

} </script>

<html> <head><title>UpperCase</title></head> <body>

Make It Upper

<form id="Form1" runat="server">

   <input runat="server" id="TheString" type="text" />
   <input runat="server" id="Button1" type="submit" value="Proceed..." 
       OnServerClick="MakeUpper" />

Results:

   <span runat="server" id="TheResult" />

</form> </body> </html></source>