五、asp+ myweb 应用
1).概述
myweb是asp+中的一门新技术,允许一个asp+应用在没有web服务器的机器上运行,实际在
ie内部运行,可以离线地运行。开发上与服务器端的应用开发无异。
让客户可以在需要时进行安装,这叫demand install。
当用户访问一个myweb应用时,asp+首先试图从本地找到这个应用,如果找不到,则从
myweb:url处下载应用说明(manifest),如果成功,则下载整个应用并安装到本地。
myweb在ngws运行环境中执行(所以,客户端必须安装ngws运行时库),可以访问独立的
存储系统,同时,可以建立到原来安装这个应用的站点的连接。他们不能访问本地机上的资源,
以及部分com的调用(这有点类似于java中的applet)。
2).myweb管理工具
如果安装了ie55,并且安装了ngws运行时环境,则可以从浏览器工具条上选择"myweb"按扭,
(位置在工具条的最后,就像安装了金山词霸后增加的那个工具一样),或者也可以直接在浏览
器的地址栏里输入 myweb:// ,就可以进入myweb管理工具。
存在两种类型的myweb应用,一是remote的,二是local的。
可以用管理工具新安装一个myweb应用,或者直接从浏览器地址栏里输入myweb的url,后一
种情况下,如果已经安装了这个myweb应用,则将直接启动该应用。
3).开发myweb应用
跟开发一个asp+服务器应用类似,最后需要一个cab文件,用实用工具cabarc.exe生成,如:
cabarc -p -r n myweb.cab *.aspx *.html *.jpg *.css *.dll *.web
manifest文件是osd(open software description)格式,名为myweb.osd,一个例子:
<softpkg name="demo1" version="1.0">
<implementation>
<codebase href="http://somewhere.com/myweb.cab">
</implementation>
<homepage>myweb://somewhere.com/default.aspx</homepage>
<iconurl>myweb://somewhere.coom/icon.gif</iconurl>
<remoteiconurl>http://somewhere.com/icon.gif</remoteiconurl>
<author>white</author>
<source> beijing 123okey.inc</source>
<size>3000</size>
</softpkg>
4).略
5).独立存储空间
myweb不能访问本地文件系统,但可以访问由gnws提供的独立存储空间(isolatedstorage),
就像访问本地文件一样,例:
//读取数据
string _storefile="mystore";
arraylist values=new arraylist();
isolatedstoragefilestream stream = null;
try{
stream = new isolatedstoragefilestream(_storefile,filemode.open);
}catch(exception e){}
if(null!=stream){
values=(arraylist)binaryserializer.deserialize(stream);
stream.close();
}
//保存数据
isolatedstoragefilestream stream;
stream = new isolatedstoragefilestream(_stroefile,filemode.openorcreate);
arraylist values = new arraylist();
values.add("test1");
……
binaryserializer.serializer(values,stream);
stream.close();
使用上例时注意需要引入名称空间:
system.io;
system.io.isolatedstorage;
system.runtime.serialization.formatters;
6).离线数据同步
现在这个版本的myweb还不支持自动地实现同步。
可以用myweb.connected属性判断当前是否连在网上。
六、cache服务
caching动态产生的内容叫output catching。
caching专门的对象叫data catching。
asp+中提供了专门的cache引擎。
1).output caching
设置response的expiration/validation,仅对get和head有效,支持url中的参数,完全相同
时使用catching中的内容。内容缺省地将在cache中保存60分钟。
要让一个.aspx文件被caching,仅需要加一行:
<%@ outputcache duration="60" %>
上面的60指60秒。
要实现更多的控制,如下:
response.cache.setexpires(datetime.now.addseconds(60));
response.cache.setcacheability(httpcacheability.public);
或者:
setexpires(datetime.now.addseconds(60));
setcacheability(httpcacheability.public);
setslidingexpiration(true);
2).data caching
cache引擎可以让你把对象保存到其中,只有应用重启后才需要重建cache。是一个字典接口,如:
cache["mykey"]=myvalue;
myvalue = cache["mykey"];
if(myvalue!=null)
……
还可以支持清除,过期等,以及文件和键值以来(可以用于统计图形,记数器等)。
例:
source = (dataview)cache["mydataset"];
if(source == null){
……
source = new dateview(ds.tables[0]);
cache["mydataset"] = source;
}
文件依赖:
cache.insert("mydata",source,new cachedependency(server.mappath("authors.xml")));
时间过期:
cache.insert("mydata",source,null,datetime.now.addhours(1),timespan.zero);
注意,为了防止资源访问中的冲突,必须对资源访问进行同步,如:
private static string cachesynchronize;
lock(cachesynchronize)
{……
}
七、配置
asp+中使用文件做配置。
在其中,也可以配置自己的信息。
1).配置文件格式
文件名为config.web,应用当前应用及其自目录下的应用。
winnt\complus\<version>\config.web是整个系统的缺省配置。config.web不可能被浏览器
访问到,即便放在web应用的目录下。
配置文件中分成两小节,第一节指出谁来处理配置信息,第二小节是具体的配置数据。
标准的asp+配置处理器有:
<httpmodules> 处理所有的请求
<httphandlers> 将特定的url映射到特定的处理器,子目录中应用不继承该配置。参考前面
的http处理器和工厂。
<sessionstate> session状态处理器
<globalization>
<compilation> 编译相关的处理
<trace> asp+ trace服务
<security> asp+安全模块
<iisprocessmodel> iis处理模块
<browsercaps> 处理浏览器兼容信息的设置
2).获取配置信息
可以用api直接访问配置信息,比如request.browser对象的属性直接获得browsercapabilities
或者调用context.getconfig,比如:
customconfigsettings config=(customconfigsettings)context.getconfig("customconfig");
if(config.enabled==true)
……
getconfig可有第二个参数获得指定的url的配置。
下面是一个保存应用自己的配置数据的例:
<configuration>
<configsections>
<add name="databases" type="system.web.configuration.dictionarysectionhandler" />
</configsections>
<databases>
<add key="pubs" value="server=localhost;uid=sa;pws="/>
<add key="nothwind" value="server=localhost;uid=sa"/>
</databases>
</configuration>
使用:
string dsn = (string)((hashtable)context.getconfig("databases"))["pubs"];
