Asp.Net较之经典的ASP执行效率上提高了很多,因为一次编译后就可以多次执行了。 但是某些情况下我们又需要能够实时修改服务器上的代码,而不用在进行重新编译dll部署上去。
其实Asp.Net也可以解释执行,以下为示例代码
示例一
<%@ Page Language=
"
C#
"
%>
< html >
< head >
< title >ASP.NET 解释执行 示例一 </ title >
</ head >
< body >
调用系统函数 当前时间: <%=System.DateTime.Now.ToString() %>
</ body >
< html >
< head >
< title >ASP.NET 解释执行 示例一 </ title >
</ head >
< body >
调用系统函数 当前时间: <%=System.DateTime.Now.ToString() %>
</ body >
</html>
示例二
<%@ Page Language=
"
C#
"
%>
< html >
< head >
< title >ASP.NET 解释执行 示例二 </ title >
</ head >
< body >
调用当前页面函数: <%=SayHello( " Calvin ") %>
</ body >
</ html >
< script runat ="server" >
private string SayHello(string name)
{
return "Hello "+name;
}
</ script >
< html >
< head >
< title >ASP.NET 解释执行 示例二 </ title >
</ head >
< body >
调用当前页面函数: <%=SayHello( " Calvin ") %>
</ body >
</ html >
< script runat ="server" >
private string SayHello(string name)
{
return "Hello "+name;
}
</ script >
示例三
<%@Page Language="C#" CodeFile="AspPage.cs" Inherits="AspPage" %>
<
html
>
< head >
< title >ASP.NET 解释执行 示例三 </ title >
</ head >
< body >
<%=SayHello( " Calvin ") %>
</ body >
</ html >
< script runat ="server" >
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("调用后台页面AspPage<br />");
// Response.End();
}
</ script >
< head >
< title >ASP.NET 解释执行 示例三 </ title >
</ head >
< body >
<%=SayHello( " Calvin ") %>
</ body >
</ html >
< script runat ="server" >
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("调用后台页面AspPage<br />");
// Response.End();
}
</ script >
其中AspPage.cs内容如下
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
public partial class AspPage : Page
{
protected string SayHello( string name)
{
return string.Format( " Hello {0}, Current DateTime is {1} ", name, System.DateTime.Now.ToString());
}
}
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
public partial class AspPage : Page
{
protected string SayHello( string name)
{
return string.Format( " Hello {0}, Current DateTime is {1} ", name, System.DateTime.Now.ToString());
}
}