ASP.NET中的开发asp如何浅谈?

2012 年 12 月 5 日7670

欢迎进入.NET社区论坛,与300万技术人员互动交流 >>进入

ASP.NET中的开发asp如何浅谈呢?先来说一下几个要认识的参数,然后举例说明Net开发asp如何用?

(1)OutPutCache

首先说下几个重要的参数

1)Duration 页或者用户控件进行开发asp的时间(单位为秒)

2)VaryByparam分号分割的字符串列表,用于使输出开发asp发生变化,这些字符串与GET方法发送的查询字符串相对应,与POST发送的参数相对应,如果没有varyByParam或者VarByControl的时候页面将报错,如果不希望浅谈任何参数来改变指定内容请将值设置为None,否则为*

3)VaryByCustom 表示自定义输出开发asp的任意版本,如果赋予给属性browser,开发asp将随浏览器版本和主要版本信息的不同而异

(1)如果页面有开发asp的时间大于用户控件的开发asp时间则页的输出开发asp时间优先

<%@ Page Language=“C#” %>

<%@ OutputCache Duration=“50” VaryByParam=“none” %>

<%@ Register src=“WebUserControl.ascx” tagname=“WebUserControl” tagprefix=“uc1” %>

<form id=“form1” runat=“server”>

<div>

<%Response.Write(DateTime.Now.ToString());%>

</div>

<uc1:WebUserControl ID=“WebUserControl1” runat=“server” />

</form>

<%@ Control Language=“C#” ClassName=“WebUserControl” %>

<%@ OutputCache Duration=“20” VaryByParam=“none” %>

<mce:script runat=“server”></mce:script>

下面是自定义控件的:

<%Response.Write(DateTime.Now.ToString());%>

(2)上面是在页面中定义开发asp在web.config中定义如下代码(然后再页面中调用也行!)

<caching>

<outputCacheSettings>

<outputCacheProfiles>

<add name=“CacheProfile” duration=“30” enabled=“true”/>

</outputCacheProfiles>

</outputCacheSettings>

</caching>

下面说的是开发asp后替换(动态更新开发asp页的部分)

{

1.以声明方式浅谈 Substitution 控件。

2.以编程方式浅谈 Substitution 控件 API.

3.以隐式方式浅谈 AdRotator 控件。

}

(2)Substitution 指定输出开发asp页上已动态内容替换该控件的部分

实例代码如下

<%@ Page Language=“C#” %>

<%@ OutputCache Duration=“30” VaryByParam=“none” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://http://www.zjjv.com///TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<mce:script runat=“server”><!--

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = DateTime.Now.ToString();

}

//当Substitution控件执行GetCurrentDateTime这个方法的时候该方法必须匹配

//HtttpresponseSubstitutionCallback的委托签名

public static string GetCurrentDateTime(HttpContext Content)

{

return DateTime.Now.ToString();

}

// --></mce:script>

<html xmlns=“http://http://www.zjjv.com///1999/xhtml”>

<head runat=“server”>

<title>无标题页</title>

</head>

<body>

<form id=“form1” runat=“server”>

<div>

<p>下面是无开发asp的</p>

<asp:Substitution ID=“Substitution1” runat=“server” MethodName=“GetCurrentDateTime” />

<br />

<p>下面是有开发asp的</p>

<asp:Label ID=“Label1” runat=“server” Text=“”></asp:Label>

</div>

</form>

</body>

</html>

(3)设置页的可开发asp性

页或者自定义控件的可开发asp性是指:是否在页的生命周期内在设备上开发asp页,可开发asp页的设备包括:发出请求的浏览器,相应请求的Web 服务器以及请求或响应流中其他任何具有开发asp功能的设备,如代理服务器。

可以浅谈HttpCacheability

NoCache 设置 Cache-Control: no-cache 标头。如果没有字段名,则指令应用于整个请求,且在满足请求前,共享(代理服务器)开发asp必须对原始 Web 服务器强制执行成功的重新验证。如果有字段名,则指令仅应用于命名字段;响应的其余部分可能由共享开发asp提供。

Private 默认值。设置 Cache-Control: private 以指定响应只能开发asp在客户端,而不能由共享(代理服务器)开发asp进行开发asp。

Server 指定响应仅开发asp在源服务器上。与 NoCache 选项相似。客户机接收 Cache-Control: no-cache 指令,但文档是在原始服务器上开发asp的。等效于 ServerAndNoCache.

ServerAndNoCache 指定响应仅开发asp在源服务器上。与 NoCache 选项相似。客户机接收 Cache-Control: no-cache 指令,但文档是在原始服务器上开发asp的。等效于 ServerAndNoCache.

Public 设置 Cache-Control: public 以指定响应能由客户端和共享(代理)开发asp进行开发asp。

ServerAndPrivate 设指示响应只能在服务器和客户端开发asp。代理服务器不能开发asp响应。

【责编:ivy】

0 0