asp.net:通过httpModule计算页面的执行时间

有时候我们想检测一下网页的执行效率。记录下开始请求时的时间和页面执行完毕后的时间点,这段时间差就是页面的执行时间了。要实现这个功能,通过HttpModule来实现是最方便而且准确的。

创建一个类库,建立如下类:

using System;   
using System.Collections.Generic;   
using System.Web;//引用web命名空间    
using System.Text;   
namespace TimerHttpModule   
{   
    
public class Class1:IHttpModule//继承IHttpModules    
    {   
           
        
public void Init(HttpApplication application)//实现IHttpModules中的Init事件    
        {   
            
//订阅两个事件    
            application.BeginRequest +=new EventHandler(application_BeginRequest);   
            application.EndRequest
+=new EventHandler(application_EndRequest);   
        }   
        
private DateTime starttime;   
        
private void application_BeginRequest(object sender, EventArgs e)   
        {   
            
//object sender是BeginRequest传递过来的对象    
            
//里面存储的就是HttpApplication实例    
            
//HttpApplication实例里包含HttpContext属性    
            starttime = DateTime.Now;   
        }   
        
private void application_EndRequest(object sender, EventArgs e)   
        {   
            DateTime endtime 
= DateTime.Now;   
            HttpApplication application 
= (HttpApplication)sender;   
            HttpContext context 
= application.Context;   
            context.Response.Write(
"<p>页面执行时间:" + (endtime - starttime).ToString() + "</p>");   
        }   
        
//必须实现dispose接口    
        public void Dispose() { }   
    }   
}

生成后将dll文件copy到bin目录,接着在web.config中注册这个HttpModule:

<configuration>    
    
<system.web>         
        
<httpModules>    
            
<add name="TimerHttpModule" type="TimerHttpModule.Class1"/>    
        
</httpModules>    
    
</system.web>    
</configuration> 

这样网站的每一个.net页面底部都会显示页面的执行时间了。

不过这样做要小心,因为每个.net页面末尾都会被加上执行时间,包括webservices和ashx页面,以及你可能不是用来直接做页面的.aspx页面(例如你用来输入json数据或者xml数据)。所以,为了保证安全,还必须采取有针对性的方法来避免这种情况的发生。

方法一:在Response.Write方法之前做判断,排除一些不想添加执行时间的页面,可以通过Request.URL来判断;

方法二:不要把执行时间直接添加到页面输出的尾端,而是作为一个http header输出。使用Response.AddHeader(key,value)可以实现这个愿望。

Flash幻灯片带fla源文件

flash-slider-cover.jpg

使用swf+xml结合的幻灯片程序,带fla源文件。如果要改动路径名,注意修改fla中的imgList相对路径。下载幻灯片程序:flash-slider.rar

从经验到理论

由于过去几年来的工作经历,突然间有感而发,发布了一条围脖:

 林剑锋:计划 - 实施 - 总结,这是工作的3个步骤。如果没有事先没有计划,事后没有总结,就叫做事无头无尾,成不了气候。

朋友Jas看到了,回了我4个字母:PDCA

百度一下,得到如下信息:

PDCA循环又叫质量环,是管理学中的一个通用模型,最早由休哈特(Walter A. Shewhart)于1930年构想,后来被美国质量管理专家戴明(Edwards Deming)博士在1950年再度挖掘出来,并加以广泛宣传和运用于持续改善产品质量的过程中。引用㈠

原来理论一早就有了,只是庸碌的我只有经过实际生活经验的淘洗,才会感觉到理论科学的作用。这真是:少年看红楼梦,看到的是美女如云的软玉温香,老来看红楼,看到的是人情冷暖中的家道中落。其中的味道,只有经过了,才知道。

引用㈠:百度百科:PDCA循环

成功实施海蜘蛛多线路由系统

海蜘蛛多线路由系统,虽然只是其免费版本,然而功能还是很强大的。我找了一台破旧的机器,配置大致如下:

CPU:AMD 1.5G

磁盘:20G

内存:256MB

杂牌主板。

装上两张100M的网卡,加上主板自带的1张,刚好够2条线路,相当于一个2个wan口,1个lan口的路由器。

装上海蜘蛛系统V8免费版,通过web界面进行配置,跟普通的路由器差别不大,很快就连上了。问办公室的同事,都说速度感觉快了一点。

明天再测试一下下载和上传时,带宽占用不均衡时,会不会智能转换线路吧。

拭目以待。

#2月16日更新

多线路由确实可以实现负载均衡,尤其是在PTP下载时,更可以极大地提高下载速度。迅雷的下载速度可以突破到800kb/s。

不过多线均衡也还来一些问题。由于线路经常切换,导致以Session做为身份认凭据的网站,频繁出现登陆过期的情形。

Dutory的缺点,也可以理解为Dutory的缺陷

Dutory的缺点有:

1、站内链接在文章列表页中出错。这是伪静态化引起的。因为路径的层次变了,而站内链接的保存方式是相对路径。除非改变站内链接的保存方式,否则这个BUG无法修复。

2、共用头部模板导致无法设置Keywords和Description。要改变这种情形,不能共用头部模板。

3、没有插件机制,无法增强系统功能。

用了一年Dutory,已经习惯了它的缺点。不过这次PR更新,居然降权了。不会是因为Dutory的原因吧?

使用无线网卡互连和共享上网的方法

经测试,本法可供诺基亚手机无线局域网使用(特殊公共,手动输入链接名)。

两台电脑都有无线网卡的话,是可以通过设置实现无线互连的,无须经过路由器和交换机。

环境:电脑A,电脑B 分别配有无线网卡
1、在电脑A的无线网络连接上右击,选择“属性”。
2、选择“无线网络配置”
3、点击右下角的“高级(V)”按钮设置,选中最下面的“仅计算机到计算机(特点)” 和最下面的“自动连接到非首选的网络”,点击“关闭”。
4、此时回到了上一个窗口,点中“首选网络”下面的“添加”按钮,自行输入网络名,本例中为“LJF”,将“自动为我提供密钥”的对号去掉,将数据加密选项改成“已禁用”,确定返回。
5、进入电脑A的无线网卡的 TCP/IP 属性,输入IP地址和子网掩码,此例中IP地址为 192.168.0.1,掩码为 255.255.255.0,其他不用输入,确定。
6、进入电脑B的无线网卡 TCP/IP 属性,将IP地址为 192.168.0.2,掩码为 255.255.255.0,确定即可。
7、现在查看无线网络连接,就可以看到有一个名为“LJF”的连接了,选择连接,就OK了!如果在无线网络链接中查看不到,可以自己手动添加一个。

如果要共享上网,第6步和第7步可以省去。因为windows xp在设置共享上网的时候,会自动为另外一张网卡设置IP地址、子网掩码等信息。

而与之连接的电脑B,则会自动获取同网段的IP地址。当然,如果没有自动获取,可以自行手动设置。

参考链接:两个无线网卡的互连方法及共享上网的方法

多个无线网卡互连(无AP)

图示详解

1.JPG

无线网卡的属性

2.JPG

无线网络配置

3.JPG

无线网络配置的高级界面配置

7.JPG

在无线网络配置中添加一个首选网络,配置如上图所示。注意,数据加密模式可以选择一种模式并设置密码。如果禁用,临近的任何机器都可以接入。

4.JPG

另一张网卡设置为共享。注意,如果是局域网,分配的网段是192.168.0.XXX的,网卡共享将会失败!此时需要修改局域网的网段才能顺利进行。原因是共享后,无线网卡的IP地址会自动被设置为192.168.0.1,也就是跟局域网的网关相同。这样会导致电脑无法上网。

5.JPG

无线网卡的IP设置。注意,如果共享后通过无线连接无法上网,可能是DNS无法正常解析。此时只要手动设置DNS为真正的DNS IP地址即可。具体的DNS设置可以咨询网络提供商。或者通过命令ipconfig /all查询得出(不一定准确)。

6.JPG

设置完毕,无线网卡处于断开状态。

 

万网短信平台导入通讯录技巧

帮助文档:

http://bms.hichina.com/help/page/normal_002.htm#7

帮助文档中没有说明的技巧:

1、手机号码一定要精确,11位数字,前后不能有空格。

2、六项数据一定要齐备,如果不齐备,可以用0代替。如果留空,会导致上传成功但没有导入任何记录,系统也不会提示你。

3、电子邮件公司名称的格式倒是没那么严格了。可以适当回一些信息。联系人列表中,只列出姓名、电话、性别、邮件。

4、允许联系人同名。

FCKeditor插件开发的一些知识

1.在fckplugin.js中,可以直接引用FCK对象进行各种操作。

2.弹窗型的插件,使用如下注册方式:

FCKCommands.RegisterCommand('PluginName',new FCKDialogCommand(parameters...));

3.选区型插件(Selection Based)似乎没有可以直接使用的Command类型,so,自己动手写一个也挺简单:

var FCKPLinkCommand = function(){}

FCKPLinkCommand.prototype = {

Name: 'PLink',

Execute:function(parameters...){},

GetState:function(){}

};

再传入注册函数即可:

FCKCommands.RegisterCommand('PLink',new FCKPLinkCommand(parameters...));

4.FCK中的函数都是大写开头的,JavaScript内致函数,都是小写开头的。例如Selection是FCK提供的,selection是JavaScript提供的。

5.工具栏图标的大小是16x16相素,如果图标大了,火狐会自动调节,IE嘛,被截掉一段。

6.选区操作区分浏览器。

IE:FCK.EditorDocument.selection.createRange().text;

火狐:FCK.EditorWindow.getSelection();

更多关于选区操作的函数参考这里:http://hi.baidu.com/17docnet/blog/item/a2ea22f4eede7422bc310988.html

摘录如下:

FCKeditor Selection 对象使用举例:
// The selection object
FCKeditorAPI.GetInstance("FCKeditor").Selection
// properties
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType();
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetSelectedElement();
FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement(); // Doesn't seem to be working in Fx when the selection is only one character
// methods
// select node, e.g. select the parent node
FCKeditorAPI.GetInstance("FCKeditor").Selection.SelectNode(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement());
// Move cursor position before (toStart = true, default) or after (toStart = false) the selection
FCKeditorAPI.GetInstance("FCKeditor").Selection.Collapse(toStart);
// Check if the selection has a specified ancestor node, returns true or false. The "nodeTagName" parameter must be Upper Case.
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.HasAncestorNode(nodeTagName));
// Move selection to ancestor node. The "nodeTagName" parameter must be Upper Case.
FCKeditorAPI.GetInstance("FCKeditor").Selection.MoveToAncestorNode(nodeTagName);
// Delete selection
FCKeditorAPI.GetInstance("FCKeditor").Selection.Delete();
// so to get the element that is selected, first check the type of the selection
// Doesn't seem to be working in Fx when the selection is only one character - This is due to some bug in the 'GetParentElement' method
if(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType() == 'Control')
{
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetSelectedElement());
}
else if(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetType() == 'Text')
{
alert(FCKeditorAPI.GetInstance("FCKeditor").Selection.GetParentElement());
}
// Fetching the actual content of the selection can't be done through the 'Selection' Object...
if (document.all)
{
alert(FCKeditorAPI.GetInstance("FCKeditor").EditorDocument.selection.createRange().text);
}
else
{
alert(oSel = FCKeditorAPI.GetInstance("FCKeditor").EditorWindow.getSelection());
}

API参考:
GetParentBlock = function(){var A=this.GetParentElement();while (A){if (FCKListsLib.BlockBoundaries[A.nodeName.toLowerCase()]) break;A=A.parentNode;};return A;}
ApplyStyle = function(A){FCKStyles.ApplyStyle(new FCKStyle(A));}
GetType = function(){try{var A=FCK.EditorDocument.selection.type;if (A=='Control'||A=='Text') return A;if (FCK.EditorDocument.selection.createRange().parentElement) return 'Text';}catch(e){};return 'None';}
GetSelectedElement = function(){if (this.GetType()=='Control'){var A=FCK.EditorDocument.selection.createRange();if (A&&A.item) return FCK.EditorDocument.selection.createRange().item(0);};return null;}
GetParentElement = function(){switch (this.GetType()){case 'Control':var A=FCKSelection.GetSelectedElement();return A?A.parentElement:null;case 'None':return null;default:return FCK.EditorDocument.selection.createRange().parentElement();}}
GetBoundaryParentElement = function(A){switch (this.GetType()){case 'Control':var B=FCKSelection.GetSelectedElement();return B?B.parentElement:null;case 'None':return null;default:var C=FCK.EditorDocument;var D=C.selection.createRange();D.collapse(A!==false);var B=D.parentElement();return FCKTools.GetElementDocument(B)==C?B:null;}}
SelectNode = function(A){FCK.Focus();FCK.EditorDocument.selection.empty();var B;try{B=FCK.EditorDocument.body.createControlRange();B.addElement(A);}catch(e){B=FCK.EditorDocument.body.createTextRange();B.moveToElementText(A);};B.select();}
Collapse = function(A){FCK.Focus();if (this.GetType()=='Text'){var B=FCK.EditorDocument.selection.createRange();B.collapse(A==null||A===true);B.select();}}
HasAncestorNode = function(A){var B;if (FCK.EditorDocument.selection.type=="Control"){B=this.GetSelectedElement();}else{var C=FCK.EditorDocument.selection.createRange();B=C.parentElement();};while (B){if (B.tagName==A) return true;B=B.parentNode;};return false;}
MoveToAncestorNode = function(A){var B,oRange;if (!FCK.EditorDocument) return null;if (FCK.EditorDocument.selection.type=="Control"){oRange=FCK.EditorDocument.selection.createRange();for (i=0;i
Delete = function(){var A=FCK.EditorDocument.selection;if (A.type.toLowerCase()!="none"){A.clear();};return A;}

7.editor/_source/commandclass/fck_othercommands.js这里定义了FCKDialogCommand。

editor/_source/internal/fckcommands.js这里定义了大部分命名的Command,例如Source,Preview,Save等等在commandclass文件夹下找不到的command.

autogrow:让FCKeditor高度随内容增加的插件

这个插件在默认情况下可能运行不正常,必须做一点修改才可以。

打开插件所在文件:/editor/plugins/autogrow/fckplugin.js

找到第65行:

window.frameElement.height = iMainFrameSize ;

将其修改为:

if (window.frameElement.style.height) {

            window.frameElement.style.height = iMainFrameSize;

        }
        else {
            window.frameElement.height = iMainFrameSize;

        }

这样就可以兼容IE和火狐浏览器了。

启用插件:

打开文件:/fckeditor/fckconfig.js

启用这两行:

FCKConfig.Plugins.Add( 'autogrow' ) ;
FCKConfig.AutoGrowMax = 600 ;

AutoGrowMax是限制最高高度。可以根据需要自行设置。

参考:http://cksource.com/forums/viewtopic.php?f=6&t=10214&p=30094

FCKeditor退休了,HTML中调用FCKeditor的方式

取而代之的是其弟弟 CKeditor 。在考虑要不要把项目中的FCK换掉。

在换掉之前,先备忘一下HTML方式调用FCKeditor的方法。

文档:FCKeditor使用指南.pdf

公告栏

  • 姓名:林剑锋(不见不散)
  • 来自:中国-广州
  • 简介:潮汕人,出生于广东揭西。醉心于Web开发8年,挑战了一年整体策划和网站运营。目前就职于平成混媒IT部。
  • Email/QQ:admin@ljf.cn

QQ群:设计学院 68075618,网站设计师 9908776

统计

文章:335篇
评论:163条 (2条Spam)
相册:1个 (120张图片)
主题:Nagrand新主题

www.ljf.cn网站PR查询