ASP.NET应用程序设置文件

ASP.NET应用程序的两种设置文件:

  • global.asax:全局应用程序设置文件;
  • web.config:基于XML的应用程序配置文件。

一、global.asax文件可以定义应用程序级和会话级的变量、对象和数据及相关事件的处理程序。该文件位于Web应用程序或网站的根目录下,当应用程序的资源或URL首次被激活或请求时,ASP.NET将其global.asax文件编译为从HttpApplication类派生而来的一个类。

编译指令:

  • @Assembly:向web应用程序注册编译后组合体
    <%@ Assemble Name="My.dll" %>
  • @Import:显式地导入名称空间
    <%@ Import Namespace="System.IO" %>
  • @Application:定义供ASP.NET Web应用程序使用的特定应用程序信息。
    <%@ APPLICATION INHERITS="myClass" DESCRIPTION="..." %>

Object标记用来声明静态对象或COM/COM+组件

  1. <Object id="id" runat="server" class="myClassName" scope="pipeline"/>
  2. <Object id="id" runat="server" progid="MyCOM-ProgID" scope="session"/>
  3. <Object id="id" runat="server" classid="MyCOM-ClasID" scope="application"/>

会话事件:Session_OnStart / Seesion_OnEnd

二、页面语法

  1. 页面编译指令:@Page、@Control、@Import、@Register、@Assembly、@OutputCache
    代码申明块:
    <script runat="server" language="vb/jscript/c#" Src="pathname">
         Code goes here...
    </script>
  2. 代码交付块:<% Inline code or expression %>
  3. 服务器端注释:<%- Commented out code or content -%>
  4. 自定义服务器控件的语法:
    <tagprefix:tagname id="OptionalID" attributename="value" attributename-propertyname="value" eventname="eventhandlemethod" runat="server" />

    <tagprefix:tagname id="OptionalID" runat="server"> </tagprefix:tagname>
  5. 数据绑定表达式:<%# databinding expression%>
    <%# DataBinder.Eval(Container.DataItem, "IntergerValue", "{0:c}") %>
    <%# (bool)DataBinder.Eval(Container.DataItem, "BoolValue") %>
  6. 服务器端包含编译指令的用法:<!- #include pathtype=filename ->

三、ASP.NET中常用的对象和类

  1. Application对象(HttpApplication类)
  2. Request对象(HttpRequest类)
  3. Response对象(HttpResponse类)
  4. Server对象(HttpServerUtility类)

四、跟踪ASP.NET应用程序

  1. 页面级跟踪:<%@ Page Trace="true" %>
  2. 应用程序级跟踪:必须在web.config中添加Trace配置段。
  3. Trace对象(TraceContext类):
    属性:IsEnabled、TraceMode(SortByTime / SortByCategory);
    方法:Write、Warn.
  4. 跟踪日志查看程序:trace.axd
    http://localhost/trace.axd

五、web.config通常位于web应用程序的根目录中,其设置被应用到所有的子目录,但子目录也可以有自己的web.config文件。

  1. <configSections>
  2. <appSettings>:
    <appSettings>
        <add key="appName" value="..." />
        <add key="appAuthor" value=".." />
    </appSettings>
    < configuration >
       
    < appSettings >
           
    < add  key ="appName"  value ="..."   />
           
    < add  key ="appAuthor"  value =".."   />
       
    </ appSettings >
    </ configuration >

    <%=ConfigurationSettings.appSettings("appName") %>
    <%=ConfigurationSettings.appSettings("appAuthor") %>
  3. <system.web>:
    开发配置:<compilation>、<customErrors>、<trace>;
    环境配置:<browserCaps>、<globalization>、<pages>;
    IIS配置:<processModel>;
    安全配置:<authentication>、<authorization>、<identity>;
    状态管理配置:<sessionState>.
  4. <location>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值