ASp.NET基础知识

一、什么时候要运行aspnet_regiis.exe -i命令
当先安装.net framework再安装IIS就要运行命令向IIS注册.net framework,注册完成后,会在C:\inetpub\wwwroot文件夹下多出一个aspnet_client的文件夹。

 

二、Web应用程序根目录运算符
1、直接以URL表示,如:

<img src=http://www.xxxxx.com/images/logo.jpg />

2、以相对于当前网页的形式表示,如:
<img src="images/logo.jpg" />

3、以相对于网站根目录的方式表示,如:
<img src="http://images.cnblogs.com/book.jpg"/>

4、以当前页面路径相等的路径形式表示,如:
<img src="../images/logo.jpg">//".."表示当前目录的上级目录

在ASP.NET还有一种只能用于服务器控件上或者服务器代码里的表示形式,那就是“~”路径表示符,如:
<asp:image ID="image1" runat="server" imageUrl="~/images/logo.jpg"/>

三、<%%>表达式
1、<%%>用来在前台编写程序的代码部分。在其中可以声明变量和方法。

<%
 
string  name = Request.Form[ " userName " ].Trim(); // Trim()方法去掉空格
  string  userName;
 
if (Request.Cookies[ " UserName " != null ])
 {
    userName
= Request.Cookies[ " UserName " ].Value;
 }
%>

 

2、<%=%>用来在前台向输出后台变量的值

<% int  i = 6 ; %> <%= i %> 等价
<%= Page.IsPostBack %>

 

 3、<%@ %>主要用于在web页面定义Page、引入控件、组件、设置Cache等:

   <% @ Page  %>
  
<% @ Assembly  %>
  
<% @ Import  %>
  
<% @ MasterType  %>
  
<% @ OutputCache  %>
  
<% @ PreviousPageType  %>
  
<% @ Reference  %>
  
<% @ Register  %>

 

 4、<%# %>主要用来绑定后台数据到前台,一般在后台都需要有对应的DataBind()在执行绑定

ExpandedBlockStart.gif 表达式
       < asp:GridView ID = " gvProducts "  runat = " server " >
            
< Columns >
                
< asp:TemplateField >
                    
< ItemTemplate >
                        
<% # Eval( " ProductName " %>
                    
</ ItemTemplate >
                
</ asp:TemplateField >
            
</ Columns >
      
</ asp:GridView >

 

5、<%: %>在asp.net mvc项目中绑定ViewData

<% : ViewData[ " Message " %>

 

6、<%$ %>用于在全球化解决方案中,指定前台页面对应的资源项:

< asp:Label ID = " lblAmount "  runat = " server "  Text = " <%$ Resources:TestSiteResources, TotalAmount %> " ></ asp:Label >

 

 三、aspx的头部分代码
新建一个名为index的aspx文件,在前台页面会看到如下内容:

<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " index.aspx.cs "  Inherits = " index "   %>

 

@Page是一个页面指令,在这里Language="C#"指明了当前页面采用的后台代码是C#语言,CodeFile="index.aspx.cs"表示这个页面对应的页代码文件是index.aspx.cs这个文件,Inherits="index"表示当前aspx页继承自Home这个类。
页代码(后置文件)文件声明

public   partial   class  index : System.Web.UI.Page

 

从这部分代码可以看出index类是继承自System.Web.UI.Page类的。注意这里还有一个C#2.0的关键字partial,这个关键字表示当前代码是一个局部类,以表示这个类是构成整个Web页面窗体的一部分。Web服务器运行这个页面的时候最终会将aspx页面和对应的页代码编译成一个类文件,然后生成IL代码。
代码页面分离模式的好处是页面展示部分和逻辑控制部分的代码分离开来,便于管理和维护。

 

转载于:https://www.cnblogs.com/aito/archive/2010/08/07/1794621.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值