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

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

Application Directory Structure

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


ASP.NET Application Folders

\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>


ASP.NET Page Directives

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] %>


directives in ASP.NET

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.


@Page directive

@Page directive sets attributes and values for an ASP.NET page (.aspx).
<%@ Page Language="VB" 
         AutoEventWireup="false" 
         CodeFile="Default.aspx.vb"
         Inherits="_Default" %>


Page Directives, code section and layout

<!-- Directives --> 
<%@ Page Language="C#" %>
<!-- Code Section --> 
<script runat="server">
private void MakeUpper(object sender, EventArgs e)
{
    string buf = TheString.Value;
    TheResult.InnerHtml = buf.ToUpper();
}
</script>
<!-- Layout --> 
<html>
<head><title>UpperCase</title></head>
<body>
<h1>Make It Upper</h1>
<form id="Form1" runat="server">
    <input runat="server" id="TheString" type="text" />
    <input runat="server" id="Button1" type="submit" value="Proceed..." 
        OnServerClick="MakeUpper" />
    <hr>
    <h3>Results:</h3>
    <span runat="server" id="TheResult" />
</form>
</body>
</html>