1、sql注入漏洞。
解决办法:使用存储过程,参数不要用字符串拼接。简单改进办法:使用SqlHelper和OledbHelper
2、跨站脚本漏洞
解决办法:“默认禁止,显式允许”的策略。具体参考:从客户端检测到有潜在危险的Request.Form值,禁止提交html标记(等被转义成
3、上传漏洞
解决办法:禁止上传目录的运行权限。只给读取权限。另外要禁止上传非法类型文件。不仅仅是aspx类型,包括很多,甚至htm、html类型文件也不应该直接上传保存。
4、数据库连接帐号,尽量使用最低权限的帐号。一定不要给管理员权限。
假如被黑客得知了数据库的密码。
那我们就可以执行任意系统命令了。
例如:xp_cmdshell 'dir c:\'
另外还有
tasklist
taskkill
pslist
pskill
net user
net user guest /active:yes
net user hack hack /add
net user hack /del
net localgruop administrators hack /add
query user
logoff 1
这些命令是不是很恐怖?呵呵。所以一定不要给web数据库连接帐号管理权限。
5、用户登录。这里不要把用户标识明文存储在cookie里,以用来标识用户是否登录。因为cookie是可以被修改的。请看这里的修改cookie,冒充其他用户。nc httpwatch使用视频教程,用微软的Forms窗体身份验证和角色一般情况都够用了。
6、如果网站程序中用到读写文件,一定要慎重,因为读取的操作很可能被黑客利用,例如用一个查看图片的aspx文件读取web.config,用一个生产模板的功能生成木马。
7、充分利用验证码。用户登录、评论等等可能会被提交垃圾信息的地方,都要使用验证码,而且要有一个安全的验证码。才能防止被暴力破解,防止网站充满垃圾数据。
8、代码要严谨,修改用户资料、修改用户数据都要跟用户关联起来,比如update news set title='新的标题' where id=新闻编号,这里还要加一个限制:userid=用户编号,这样可以防止一个人修改别人的新闻。
9、关闭web.config中的错误显示。
以上是程序方面的安全问题,想到哪里就写到哪里。没有系统的整理。
另外顺便提提服务器安全问题。
1、开启windows防火墙,关闭不用的端口。这点是最重要的。就是说你提供的服务越少,你的服务器就越安全。
2、设置安全的密码。复杂度要达到一定强度。定期修改密码。密码不要泄露给别人,包括机房管理员。如果必要告诉机房人员,待机房人员用完密码以后立刻改掉。
3、安装ARP防火墙。机房里ARP病毒非常多,如果中了ARP病毒,轻者浏览网站不正常,可能有木马跟随。严重的就整个网站、机房都断网了。
4、适当的安装杀毒软件。(诺顿、麦咖啡等)
5、IIS关闭不用的服务,例如asp支持,关闭不用的服务:ftp,smtp,pop3等等,修改网站根目录。设置目录权限。
6、针对各种攻击,有不同的对策,例如cc攻击。曾经遇到一次,深圳那边有5台连续IP的机器对我的一个视频站发动CC攻击,导致网站打开非常的慢,开始我们还不知道是被攻击,以为程序有漏洞,不停的找程序的问题。后来通过服务器安全管理软件,查出是这些IP在作怪,通过站长屏蔽IP访问的几种方法中提到的“本地安全策略”方法屏蔽掉这5个IP以后服务器恢复正常,网站恢复了往日的速度。
常用命令:iisapp -a,netstat -nao,tasklist,telnet xxx.xxx.xxx.xxx 端口
7、远程管理软件不要用默认端口,虽然密码被暴力破解和猜到的可能很小,但是总是有无聊的人尝试。造成日志里一堆垃圾信息。修改端口以后就没有人尝试破解密码了。因为他跟不知道这个端口是做什么的。谈到这里,我想起,不用的服务要关闭,那么用的服务器就要开启吗?那肯定是要启动的,不启动谁都用不了了,这里可以做一个限制,比如我的smtp服务只提供本机使用,那么我从防火墙里把25端口关闭,如果我的SQL SERVER只是供本机使用的。那么我也从防火墙里吧1433端口关闭。这样外部无法连接,自然也不存在暴力破解数据库密码了。windows防火墙还可以针对某一个IP开放某个端口。还是比较强大的。
以上乱七八糟的谈了一堆,希望对站长和程序员们有所帮助,大家可以加我QQ:4111852交流。我非常的欢迎。
最后说一下那个网友被挂马的解决建议:
1、备份好数据库、其他数据。
2、把所有程序、包括目录全部删除,以确保没有文件被留后门。
3、如果有可能,检查服务器安全,确保服务器没有被建立后门,例如超级帐号、安装了后门木马。这样的话,你怎么修改你的程序都没用,人家随时可以修改你的程序。
4、另一个网友提到的办法,上传一个静态文件test.html,访问一下看看,是不是也有木马以排除网络问题。
5、如果4中,确认不是网络问题,那就是文件被挂马了,全部程序删除,上传自己的安全的备份,恢复数据,检查数据库,确保木马不在数据库中。
6、查看IIS日志,看谁登录过后台,参考:iis日志分析视频教程
(字节数 : 3834)
jQuery 是继 prototype 之后又一个优秀的 Javascript 框架。其宗旨是—写更少的代码,做更多的事情。它是轻量级的 js 库(压缩后只有21k) ,这是其它的 js 库所不及的,它兼容 CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)。 jQuery 是一个快速的,简洁的 javaScript 库,使用户能更方便地处理 HTML documents、events、实现动画效果,并且方便地为网站提供 AJAX 交互。 jQuery 还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。 jQuery 能够使用户的 html 页保持代码和 html 内容分离,也就是说,不用再在 html 里面插入一堆js来调用命令了,只需定义 id 即可。今天在Kollermedia.at上发现了一篇JQuery插件列表的文章,特推荐如下。
文件上传(File upload)
Ajax File Upload.
jQUploader.
Multiple File Upload plugin.
jQuery File Style.
Styling an input type file.
Progress Bar Plugin.
表单验证(Form Validation)
jQuery Validation.
Auto Help.
Simple jQuery form validation.
jQuery XAV - form validations.
jQuery AlphaNumeric.
Masked Input.
TypeWatch Plugin.
Text limiter for form fields.
Ajax Username Check with jQuery.
表单-选取框(Form - Select Box stuff)
jQuery Combobox.
jQuery controlled dependent (or Cascadign) Select List.
Multiple Selects.
Select box manipulation.
Select Combo Plugin.
jQuery - LinkedSelect
Auto-populate multiple select boxes.
Choose Plugin (Select Replacement).
表单基本、输入框、选择框等(Form Basics, Input Fields, Checkboxes etc.)
jQuery Form Plugin.
jQuery-Form.
jLook Nice Forms.
jNice.
Ping Plugin.
Toggle Form Text.
ToggleVal.
jQuery Field Plugin.
jQuery Form’n Field plugin.
jQuery Checkbox manipulation.
jTagging.
jQuery labelcheck.
Overlabel.
3 state radio buttons.
ShiftCheckbox jQuery Plugin.
Watermark Input.
jQuery Checkbox (checkboxes with imags).
jQuery SpinButton Control.
jQuery Ajax Form Builder.
jQuery Focus Fields.
jQuery Time Entry.
时间、日期和颜色选取(Time, Date and Color Picker)
jQuery UI Datepicker.
jQuery date picker plugin.
jQuery Time Picker.
Time Picker.
ClickPick.
TimePicker.
Farbtastic jQuery Color Picker Plugin.
Color Picker by intelliance.fr.
投票插件(Rating Plugins)
jQuery Star Rating Plugin.
jQuery Star Rater.
Content rater with asp.net, ajax and jQuery.
Half-Star Rating Plugin.
搜索插件(Search Plugins)
jQuery Suggest.
jQuery Autocomplete.
jQuery Autocomplete Mod.
jQuery Autocomplete by AjaxDaddy.
jQuery Autocomplete Plugin with HTML formatting.
jQuery Autocompleter.
AutoCompleter (Tutorial with PHP&MySQL).
quick Search jQuery Plugin.
编辑器(Inline Edit & Editors)
jTagEditor.
WYMeditor.
jQuery jFrame.
Jeditable - edit in place plugin for jQuery.
jQuery editable.
jQuery Disable Text Select Plugin.
Edit in Place with Ajax using jQuery.
jQuery Plugin - Another In-Place Editor.
TableEditor.
tEditable - in place table editing for jQuery.
多媒体、视频、Flash等(Audio, Video, Flash, SVG, etc)
jMedia - accessible multi-media embedding.
JBEdit - Ajax online Video Editor.
jQuery MP3 Plugin.
jQuery Media Plugin.
jQuery Flash Plugin.
Embed QuickTime.
SVG Integration.
图片(Photos/Images/Galleries)
ThickBox.
jQuery lightBox plugin.
jQuery Image Strip.
jQuery slideViewer.
jQuery jqGalScroll 2.0.
jQuery - jqGalViewII.
jQuery - jqGalViewIII.
jQuery Photo Slider.
jQuery Thumbs - easily create thumbnails.
jQuery jQIR Image Replacement.
jCarousel Lite.
jQPanView.
jCarousel.
Interface Imagebox.
Image Gallery using jQuery, Interface & Reflactions.
simple jQuery Gallery.
jQuery Gallery Module.
EO Gallery.
jQuery ScrollShow.
jQuery Cycle Plugin.
jQuery Flickr.
jQuery Lazy Load Images Plugin.
Zoomi - Zoomable Thumbnails.
jQuery Crop - crop any image on the fly.
Image Reflection.
Google地图(Google Map)
jQuery Plugin googlemaps.
jMaps jQuery Maps Framework.
jQmaps.
jQuery & Google Maps.
jQuery Maps Interface forr Google and Yahoo maps.
jQuery J Maps - by Tane Piper.
游戏(Games)
Tetris with jQuery.
jQuery Chess.
Mad Libs Word Game.
jQuery Puzzle.
jQuery Solar System (not a game but awesome jQuery Stuff).
表格等(Tables, Grids etc.)
UI/Tablesorter.
jQuery ingrid.
jQuery Grid Plugin.
Table Filter - awesome!.
TableEditor.
jQuery Tree Tables.
Expandable “Detail” Table Rows.
Sortable Table ColdFusion Costum Tag with jQuery UI.
jQuery Bubble.
TableSorter.
Scrollable HTML Table.
jQuery column Manager Plugin.
jQuery tableHover Plugin.
jQuery columnHover Plugin.
jQuery Grid.
TableSorter plugin for jQuery.
tEditable - in place table editing for jQuery.
jQuery charToTable Plugin.
jQuery Grid Column Sizing.
jQuery Grid Row Sizing.
统计图(Charts, Presentation etc.)
jQuery Wizard Plugin .
jQuery Chart Plugin.
Bar Chart.
边框、圆角、背景(Border, Corners, Background)
jQuery Corner.
jQuery Curvy Corner.
Nifty jQuery Corner.
Transparent Corners.
jQuery Corner Gallery.
Gradient Plugin.
文字和超链接(Text and Links)
jQuery Spoiler plugin.
Text Highlighting.
Disable Text Select Plugin.
jQuery Newsticker.
Auto line-height Plugin.
Textgrad - a text gradient plugin.
LinkLook - a link thumbnail preview.
pager jQuery Plugin.
shortKeys jQuery Plugin.
jQuery Biggerlink.
jQuery Ajax Link Checker.
鼠标提示(Tooltips)
jQuery Plugin - Tooltip.
jTip - The jQuery Tool Tip.
clueTip.
BetterTip.
Flash Tooltips using jQuery.
ToolTip.
菜单和导航(Menus, Navigations)
jQuery Tabs Plugin - awesome! . [demo nested tabs.]
another jQuery nested Tab Set example (based on jQuery Tabs Plugin).
jQuery idTabs.
jdMenu - Hierarchical Menu Plugin for jQuery.
jQuery SuckerFish Style.
jQuery Plugin Treeview.
treeView Basic.
FastFind Menu.
Sliding Menu.
Lava Lamp jQuery Menu.
jQuery iconDock.
jVariations Control Panel.
ContextMenu plugin.
clickMenu.
CSS Dock Menu.
jQuery Pop-up Menu Tutorial.
Sliding Menu.
http://stilbuero.de/jquery/tabs_3/
幻灯、翻转等(Accordions, Slide and Toggle stuff)
jQuery Plugin Accordion.
jQuery Accordion Plugin Horizontal Way.
haccordion - a simple horizontal accordion plugin for jQuery.
Horizontal Accordion by portalzine.de.
HoverAccordion.
Accordion Example from fmarcia.info.
jQuery Accordion Example.
jQuery Demo - Expandable Sidebar Menu.
Sliding Panels for jQuery.
jQuery ToggleElements.
Coda Slider.
jCarousel.
Accesible News Slider Plugin.
Showing and Hiding code Examples.
jQuery Easing Plugin.
jQuery Portlets.
AutoScroll.
Innerfade.
拖放插件(Drag and Drop)
UI/Draggables.
EasyDrag jQuery Plugin.
jQuery Portlets.
jqDnR - drag, drop resize.
Drag Demos.
XML XSL JSON Feeds
XSLT Plugin.
jQuery Ajax call and result XML parsing.
xmlObjectifier - Converts XML DOM to JSON.
jQuery XSL Transform.
jQuery Taconite - multiple Dom updates.
RSS/ATOM Feed Parser Plugin.
jQuery Google Feed Plugin.
浏览器(Browserstuff)
Wresize - IE Resize event Fix Plugin.
jQuery ifixpng.
jQuery pngFix.
Link Scrubber - removes the dotted line onfocus from links.
jQuery Perciformes - the entire suckerfish familly under one roof.
Background Iframe.
QinIE - for proper display of Q tags in IE.
jQuery Accessibility Plugin.
jQuery MouseWheel Plugin.
对话框、确认窗口(Alert, Prompt, Confirm Windows)
jQuery Impromptu.
jQuery Confirm Plugin.
jqModal.
SimpleModal.
CSS
jQuery Style Switcher.
JSS - Javascript StyleSheets.
jQuery Rule - creation/manipulation of CSS Rules.
jPrintArea.
DOM、AJAX和其它JQuery插件(DOM, Ajax and other jQuery plugins)
FlyDOM.
jQuery Dimenion Plugin.
jQuery Loggin.
Metadata - extract metadata from classes, attributes, elements.
Super-tiny Client-Side Include Javascript jQuery Plugin.
Undo Made Easy with Ajax.
JHeartbeat - periodically poll the server.
Lazy Load Plugin.
Live Query.
jQuery Timers.
jQuery Share it - display social bookmarking icons.
jQuery serverCookieJar.
jQuery autoSave.
jQuery Puffer.
jQuery iFrame Plugin.
Cookie Plugin for jQuery.
jQuery Spy - awesome plugin.
Effect Delay Trick.
jQuick - a quick tag creator for jQuery.
Metaobjects.
elementReady.
(字节数 : 25062)
asp.net网站开发中经常需要生成静态页面。
生成静态页面的好处:
1、提升网站性能、负载能力。
2、提高网站安全性。
3、利于搜索引擎收录。
以上3点优势,足以让广大asp.net程序员对生产静态网页趋之若骛了。
本文主要讲述一种比较简单、方便的实现方法,适合交互性不多的网站使用。例如新闻资讯、产品展示等。这次讲的静态页面是生成真正的静态网页,可以脱离.net直接在IIS上运行的页面。好了,不多说了。直接贴代码吧:
核心代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://" + Request.Url.Authority + "/default.aspx";
new System.Net.WebClient().DownloadFile(url, Server.MapPath("~/default.html"));
Response.Redirect("default.html");
}
如果需要根据参数生成不同的文件,比如新闻页面,每个新闻一个文件,只需要传递不同的URL参数,和保存的文件路径即可。这里需要注意一下,获取自己网站的网页,有可能会造成“死锁”,感觉几率很少,至少我没遇到过。然后前台的链接也要修改成相应的静态页面的链接。这样整个网站就部分静态化了。而且这种开发模式的好处就是,基本不需要改变你开发的框架和自己的开发习惯。
(字节数 : 2231)
【IT168 技术文档】
NBear是一个基于.Net 2.0、C#2.0开放全部源代码的的软件开发框架类库。NBear的设计目标是尽最大努力减少开发人员的工作量,最大程度提升开发效率,同时兼顾性能及可伸缩性。
开源协议:BSD。
名称NBear的由来
N代表.Net,也代表No;Bear既可以翻译成熊,也有忍受之意。
Bear虽然是那种看起来憨憨的样子,但是攻击时身手“敏捷”,因此.Net Bear代表了NBear是一个基于.Net2.0、为敏捷开发而生的快速开发框架。
我们大多数项目的开发需要Bear(忍受)太多的不必要的重复和繁琐的配置。如数据持久化、对象池、Web开发中的URL重定向、输入验证、客户端脚本等等,为了简化许多常用组件充用,NBear为您提供了许多灵活的工具和组件;为了简化繁琐的配置(尤其是如nhibernate这类ORM组件的繁琐的配置文件格式、高高的学习曲线和噩梦般的需求变更时的维护更新),NBear向您提供零配置需要的数据访问(持久化)接口和可充用组件。
因此,NBear也代表No Bear,充分运用.Net2.0中的许多新技术Generic、Emit、HttpModule等,NBear让我们一起不(No)再忍受(Bear)这种种繁琐的束缚,大大提高我们的软件开发效率、需求变更时的响应效率,您会注意到,在需要您敲打的代码量(工作量)变得越来越少的同时,NBear也会带给您许多优雅高效的开发体验。
NBear适合用来开发什么样的程序?
NBear的核心包括一个泛型、强类型的的数据持久化接口、一组接口式的Entity定义组件、高性能XML/JSON序列化支持、服务工厂、分布式服务队列和Web组件,因此:
1. NBear最适合开发各类基于ASP.NET 2.0,对性能要求较高的Web程序。JSON序列化和XML序列化的结合使用将可以使您的服务端和客户端数据交互变得更简单高效;NBear.Web组件提供了许多加速Web开发的组件,将使您基于标准 ASP.NET方式的开发效率大大提高;同时,简单易用、性能突出的泛型持久化支持,则将使您能够将更多注意力集中到业务开发,同时也不会有传统ORM持久化框架的性能问题和繁琐配置需要(NBear几乎不需要配置,性能则可与DAAB相当)。
2. 高性能的XML和JSON序列化支持和灵活高效的持久化支持,也使得NBear能为开发各种类型的基于远程数据交换(Web Service、Remoting等等)的分布式应用程序提供便利。
3. 内置的基于IoC容器和分布式服务队列的服务工厂能够使您的程序拥有良好的可伸缩性,可以完全透明的将一个普通构架的程序设置为一个分布式程序,甚至不需要修改消费端或服务实现段的任何代码,基于服务工厂的系统天然就是SOA构架,这就使得您的系统可以以极小的成本和其他SOA构架进行整合。
4. 对于桌面应用程序,NBear同样是一个几乎没有什么学习曲线(多少人会为写一个小小的日历程序而仔细研究透彻Hibernate的参考手册?)、实用高效的数据持久化方案。
功能列表
·O/R映射时无需配置文件,充分利用命名约定
·接口式实体类定义,简单清晰,易于描述系统
·提供实体类生成工具,免除手写实体的工作量
·动态实体类工厂,运行时动态Emit及缓存实体类接口的实现类
·高性能实体类XML及JSON序列化
·基于Provider模式的可扩展持久化数据库源支持
·支持多数据库源
·基于范型的强类型实体持久化及数据访问接口
·基于容器的分布式服务工厂,透明的分布式服务调用和分发
·基于.Net Remoting的分布式服务队列
·扩展ASP.NET MasterPage, Pae, UserControl基类
·基于用户控件的AJAX支持
·URL重写支持
·常用UI控件
(字节数 : 2461)
Anthem.net的所有技术都是开源的,源代码下载地址为http://nchc.dl.sourceforge.net/sourceforge/anthem-dot-net/anthem-1.1.0.zip
Anthem.net技术的原理简单介绍:
让每个控件都有独立的信息提交能力,
比如在一个Button的Click事件中
private void Button1_Click(object sender, System.EventArgs e)
{
TextBox1.Text = "OK";
TextBox1.UpdateAfterCallBack = true;
}
运行的页面上,你看不到刷新,TextBox1就改变了。
其实在编译的过程中,由于我们使用的是Anthem.net控件,它会自动产生大量的javascript脚本,来实现异步交互。
那么我们只需要和往常一样在后台中写每个事件下的操作,至于是不是异步交互,我们都不用管了。
不足的是,这个开源技术目前只是1.0版本,目前只有24种可用控件,自定义控件不能直接实现独立提交的接口。
和传统的ajax技术相比,它有以下优点:
1、不需要任何技术升级,以前不会使用ajax技术的人员,按照以往的编程方式就可实现异步交互
2、支持ASP.NET 1.0 和 ASP.NET 2.0
3、开源技术,如果深入研究,也能开发出自己的控件
Anthem.NET的Callback方式。
一、普通的调用
<%@ Register TagPrefix="anthem" Namespace="Anthem" Assembly="Anthem" %>
<anthem:Button id="button" runat="server" Text="Click Me!" />
<anthem:Label id="label" runat="server" />
<script runat="server">
void button_Click(object sender, EventArgs e) {
label.Text = DateTime.Now.ToString();
label.UpdateAfterCallBack = true;
}
</script>
二、在回调前后添加自定义客户端函数的执行逻辑
几个常用的属性:
PreCallBackFunction:用于定义回调前执行的函数,通常可以在这里加入确认的判断。
在这个函数里 return false 将会取消回调。
PostCallBackFunction: 回调后执行的函数。
TextDuringCallBack: 用于定义回调过程中控件显示的提示信息(通常是提示等待的文字)
EnabledDuringCallBack: 在回调过程中,控件是否禁用。
CallBackCancelledFunction: 如果回调被取消,则会调用这个函数。
代码例子:
<anthem:Button id="button1" runat="server" Text="Click Me!" TextDuringCallBack="Working..." EnabledDuringCallBack="false" PreCallBackFunction="button1_PreCallBack" PostCallBackFunction="button1_PostCallBack" CallBackCancelledFunction="button1_CallBackCancelled" />
<script language="javascript" type="text/javascript">
// 回调之前,可在这里取消回调
function button1_PreCallBack(button) {
if (!confirm('Are you sure you want to perform this call back?')) {
return false;
}
document.getElementById('button2').disabled = true;
}
// 回调完成后
function button1_PostCallBack(button) {
document.getElementById('button2').disabled = false;
}
// 取消回调后
function button1_CallBackCancelled(button) {
alert('Your call back was cancelled!');
}
</script>
注意以上这些客户端处理函数中,都可以传递 control 本身作为参数,因此在必要的情况下这些函数是可以被重用的。(比如对一组类似的控件的回发事件进行处理)
三、调用服务器页面的方法
服务器端需要做的事情:
[Anthem.Method]
public int Add(int a, int b) {
return a + b;
}
void Page_Load() {
Anthem.Manager.Register(this);
}
客户端:
<input id="a" size="3" value="1">
<input id="b" size="3" value="2">
<button onclick="DoAdd(); return false;" type="button">Add</button>
<input id="c" size="6">
// 参数的含义依次是:
// 服务器方法的名字,
// 方法的参数(以 js 数组形式传递),
// 服务器端方法返回结果时调用的回调函数(因为是异步模式)。
Anthem_InvokePageMethod(
'Add',
[document.getElementById('a').value, document.getElementById('b').value],
function(result) {
document.getElementById('c').value = result.value;
}
);
调用后,在回调函数的参数中得到的 result 变量,是一个包含 value 和 error 两个属性的对象。如果在服务器端发生错误,则 value 为 null, 而 error 中包含错误数据。
四、如何处理回调时可能发生的异常
在页面中定义 Anthem_Error js 函数,则可处理所有回调时的未处理异常。
<script type="text/javascript">
function Anthem_Error(result) {
alert('Anthem_Error was invoked with the following error message: ' +
result.error);
}
</script>
异常也可以在服务器端处理。只要定义下列名称的方法:
void Page_Error()
{
Anthem.Manager.AddScriptForClientSideEval("window.location = 'http://anthem-dot-net.sf.net/'");
}
在服务器端处理有一些额外的好处,主要是可以将异常信息记录到日志.
五、页面跳转
在 Callback 的处理中,不能用 Response.Redirect 来处理页面跳转,因为这些函数是通过 js 的无刷新来调用的。代替的办法是用 Anthem.Manager 回传一段 js 给客户端去用 eval 的方式执行,从而达到页面跳转的效果(推而广之,这个 eval 的功能当然不限于跳转页面,可以干很多其他的事情)。
代码示例:
Anthem.Manager.AddScriptForClientSideEval("window.location = 'http://anthem-dot-net.sourceforge.net/';");
六、几个全局级别的客户端回调函数
我们可以在客户端定义几个特殊名字的函数,以供 Anthem 在每一次回调的前后调用。这些函数包括:
Anthem_PreCallBack(),
Anthem_CallBackCancelled(),
Anthem_PostCallBack(),
除此之外还包括前面说到的 Anthem_Error() 等。
这里典型的一个应用场景是,在每次回调开始后,我们在 Anthem_PreCallBack() 中创建一个“loading”信息的层,然后在取消(Anthem_CallBackCancelled) 或成功回调后(Anthem_PostCallBack),移除这个层。
这样可以很方便的模拟出类似 Gmail 中的加载效果。
七、回调过程中向页面添加了新的 js 脚本
这种情况下必须设定一个额外的属性:
Anthem.Manager.IncludePageScripts = true;
例子:
<script runat="server">
protected void button1_Click(object sender, EventArgs e)
{
HtmlButton button = new HtmlButton();
button.InnerText = "Now click me!"
button.Attributes["onclick"] = "ThankYou();"
placeholder1.Controls.Add(button);
placeholder1.UpdateAfterCallBack = true;
string script = @"<script type=""text/javascript"">
function ThankYou() {
alert('Thank you!');
}
</" + "script>"
#if V2
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), script, script);
#else
Page.RegisterClientScriptBlock(script, script);
#endif
Anthem.Manager.IncludePageScripts = true;
}
</script>
八、PreUpdate 事件
控件在 Render 之前,如果 UpdateAfterCallBack 为 true,则会引发这个事件。
目前这个事件的用途似乎不大。
大致的了解了一下Anthem.NET,感觉还是蛮不错的,至少在目前的应用中,已经足够了。:)
(字节数 : 5224)
1. BtnDel.Attributes.Add("onclick","return confirm('"+"确认删除?"+"')");
2. linktempDelete.Attributes["onclick"]="javascript:return confirm('"+"确认删除?"+"');";
3. private void grdProject_ItemDataBound(object sender, DataGridItemEventArgs e)
4.
{
if ((e.Item.ItemType == ListItemType.Item) ¦ (e.Item.ItemType == ListItemType.AlternatingItem))
{
// 刪除按鈕上的提示部分
e.Item.Cells[10].Attributes.Add("onclick", "return confirm('确定删除吗?');");
}
}
5.
<script language="JavaScript" type="text/JavaScript">
function delete_y(e)
{
if(event.srcElement.outerText == "删除")
event.returnValue=confirm("确定删除?");
}
document.onclick=delete_y;
</script>
(二).跨语言字符串替换
System.Text.RegularExpressions.Regex.Replace(str1,@" <{1}[^ <>]*>{1}","").Replace(" ","").Replace("\","\\").Replace("-","-").Replace("&","&").Replace("<"," <").Replace(">",">").Replace("br","\n");
(三).关闭窗体
1.
this.btnClose.Attributes.Add("onclick", "window.close();return false;");
2.关闭本窗体间跳转到另一个页面
this.HyperLink1.NavigateUrl = "javascript:onclick=window.opener.location.assign
('" + "index.aspx"+ "?&Func=Edit&AutoID=" + intAutoid + ');window.close();";
3.关闭父窗体:
<INPUT type="reset" value=' <%=this._Cancel%>' onclick="window.parent.close()" Class="Button">
4.关闭本弹出窗体,并刷新父页面
this.Response.Write(" <script language='javascript'>window.opener.location.reload();window.close(); </script>");
(四).Web MessageBox
1.
Response.Write(" <script language=javascript> window.alert('保存成功1'); </script>");
2.
Response.Write(" <script>alert('"+"保存成功!"+"'); </script>");
3.
this.Page.RegisterStartupScript("ChiName"," <script language='javascript'>alert('" + "保存成功!" + "') </script>");
(五).DataGrid中加CheckBox控件模板列.
请看: http://blog.csdn.net/chengking/archive/2005/10/08/497520.aspx
(六). window.open() 方法
语法:window.open(pageurl,name,parameters);
window对象的open()方法用于创建一个新的窗口实例,新创建的窗口的外观由参数:parameters指定。新窗口中打开的文档由参数: pageurl指定。系统能够根据参数:name确定的名称访问该窗口。
下表为parameters参数表:
参数 衩始值 说明
alwaysLowered yes/no 指定窗口隐藏在所有窗口之下。
alwaysRaised yes/no 指定窗口浮在所有窗口之上。
dependent yes/no 指定打开的窗口为父窗口的一个了窗口。并随父窗口的关闭而关闭。
directions yes/no 指定Navigator 2和3的目录栏是否在新窗口中可见。
height pixel value 设定新窗口的像素高度。
hotkeys yes/no 在没有菜单栏的新窗口设置安全退出热键。
innerHeight pixel value 设置新窗口中文档的像素高度。
innerWidth pixel value 设置新窗口中文档的像素宽度。
location yes/ no 指明位置栏在新窗口中是否可见。
menubar yes /no 指明菜单栏在新窗口中是否可见。
outerHeight pixel value 设定窗口(包括装饰边框)的像素高度。
outerWidth pixel value 设定窗口(包括装饰边框)的像素宽度。
resizable yes /no 指明新窗口是否可以调整。
screenX pixel value 设定新窗口离屏幕边界的像素长度。
screenY pixel value 设定新窗口离屏幕上边界的像素长度。
scrollbars yes /no 指明滚动栏在新窗口中是否可见。
titlebar yes /no 指明菜单题目栏在新窗口是否可见。
toolbar yes /no 指明工具栏在新窗口中是否可见。
Width pixel value 设定窗口的像素宽度。
z-look yes /no 在文档中包含各个 <pplet>标签的数组。
fullscreen yes / no 打开的窗体是否进行全屏显示
left pixel value 设定新窗口距屏幕左方的距离
top pixel value 设定新窗口距屏幕上方的距离
例子:
<html>
<head>
<title>window.open函数 </title>
</head>
<body>
<script language="javascript">
<!--
window.open("","name1","width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100");
//-->
</script>
</body>
</html>
(字节数 : 5372)
2.aspx文件加入
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
3.aspx文件加入
<asp:DataGrid ID="VideoAdmin" runat="server">
</asp:DataGrid>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="15" style="font-size:14px;" HorizontalAlign="Right" NumericButtonCount="6" NumericButtonTextFormatString="[{0}]" CustomInfoHTML="第 <font color='red'><b>%CurrentPageIndex%</b></font> 页 共 %PageCount% 页 显示 %StartRecordIndex%-%EndRecordIndex% 条" InputBoxStyle="width:24px; height:14px;" ShowInputBox="Always" SubmitButtonText=" GO " FirstPageText="[首 页]" PrevPageText="[上 页]" NextPageText="[下 页]" LastPageText="[末 页]" TextBeforeInputBox="转到第" TextAfterInputBox="页 " PagingButtonSpacing="10px" width="100%" ShowCustomInfoSection="Left" UrlPaging="true" OnPageChanging="AspNetPager1_PageChanging"></webdiyer:AspNetPager>
具体参数根据需求自定
4.cs文件引入命名空间
using Wuqi.Webdiyer;
6.初始化数据绑定
if (!IsPostBack)
{
string SqlStr = "select count(*) from *";
AspNetPager1.RecordCount = SqlHelper1.selcount(SqlStr); //查询记录总数赋值给AspNetPager1
//SqlHelper1.selcount是自定义操作数据库方法
DataGridDataBind(); //数据绑定DataGrid
}
7.数据绑定方法--自定义分页
private void DataGridDataBind()
{
string SqlStr = "select * from *";
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connectionStrings"]);
//创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter(SqlStr, conn);
//创建DataSet对象
DataSet ds = new DataSet();
try
{
//从指定的索引开始取PageSize条记录
da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "CurDataTable");
//填充数据集
da.Fill(ds, "AllDataTable");
//设置DataGrid控件实际要显示的项数
VideoAdmin.VirtualItemCount = ds.Tables["AllDataTable"].Rows.Count;
//进行数据绑定
VideoAdmin.DataSource = ds.Tables["CurDataTable"];
VideoAdmin.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
8.分页控件事件
protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
DataGridDataBind();
}
如要制作无刷新分页
1.添加引用
2.配置webconfig
<system.web>
<httpModules>
<add name="MagicAjaxModule" type="MagicAjax.MagicAjaxModule, MagicAjax"/>
</httpModules>
</system.web>
3.aspx页面加入<%@ Register Assembly="MagicAjax" Namespace="MagicAjax.UI.Controls" TagPrefix="ajax" %>
4.aspx页面加入
<ajax:AjaxPanel id="AjaxPanel1" runat="server">
<asp:DataGrid ID="VideoAdmin" runat="server">
</asp:DataGrid>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server">
</webdiyer:AspNetPager>
</ajax:AjaxPanel>
(字节数 : 3274)
简单的错误处理页面可以通过web.config来设置
| <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> |
如果想通过编程的方式来呈现错误原因,可以通过Page_Error事件来做这件事。
另一种方式则可以通过Global.asax来实现,我觉得这种方式较为方便,另外如果能结合一个单独的更加友好的页面,则看来起更舒服一些:
Global.asax(如果需要,可以记录错误日志)
| void Application_Error(object sender, EventArgs e) { Exception objErr = Server.GetLastError().GetBaseException(); string error = "发生异常页: " + Request.Url.ToString() + "<br>"; error += "异常信息: " + objErr.Message + "<br>"; Server.ClearError(); Application["error"] = error; Response.Redirect("~/ErrorPage/ErrorPage.aspx"); } ErrorPage.aspx protected void Page_Load(object sender, EventArgs e) { ErrorMessageLabel.Text = Application["error"].ToString(); } |
| <script language="JavaScript" type="text/Javascript"> <!-- function CheckError_onclick() { var chk = document.getElementById("CheckError"); var divError = document.getElementById("errorMsg"); if(chk.checked) { divError.style.display = "inline"; } else { divError.style.display = "none"; } } // --> </script> |
![]() |
(字节数 : 2831)
很多情况下我们用不到编辑器的很多功能,在加载的时候加载多余的功能大大降低了速度,为此我们有必要自定义显示的功能,只显示我们想要的,打开fckconfig.js定位到以下代码部分FCKConfig.ToolbarSets["Default"] 后面的Defalut是工具栏定义集合的名称,我们来看看如何去理解这些定义:
[]之间是定义行如果有多行,则要在后右加一个逗号;
-是分隔符;
Source-源代码 DocProps-页面属性 NewPage-新建 Preview-预览 Templates-模板
Cut-剪切 Copy-复制 Paste-粘贴 PasteText-粘贴为无格式文本 PasteWord-从word中粘贴 Print-打印 SpellCheck-拼写检查
Undo-撤销 Redo-重复 Find-查找 Replace-替换 SelectAll-全选 RemoveFormat-清除格式
Form-插入表单 Checkbox-插入复选框 Radio-插入单选按钮 TextField-插入文本框 Textarea-插入文本区域 Select-插入下拉框 Button-插入按钮 ImageButton-插入图片按钮 HiddenField-插入隐藏域
Bold-加粗 Italic-加斜 Underline-下划线 StrikeThrough-删除线 Subscript-上角 Superscript-下角
OrderedList-编号列表 UnorderedList-项目列表 Outdent-增加缩进 Indent-减少缩进
JustifyLeft-左对齐 JustifyCenter-居中对齐 JustifyRight-右对齐 JustifyFull-两端对齐
Link-插入/编辑超链接 Unlink-删除超链接 Anchor-插入/编辑锚点
Image-插入图片 Flash-插入flash Table-插入表格 Rule-插入水平线 Smiley-插入表情 SpecialChar-插入特殊符号 PageBreak-插入分页符 UniversalKey-软键盘
Style-样式 FontFormat-文本格式 FontName-字体 FontSize-字体大小
TextColor-文本颜色 BGColor-背景颜色
FitWindow-全屏编辑 About-关于FCK
看到这里大家都很清楚了各个按钮的意思,下面我们按自己的需要定义显示的按钮
FCKConfig.ToolbarSets["Custom"] = [
['Source','Link','Unlink','Image']
] ;
FCKConfig.ToolbarSets["NoneSet"] = [
[]
] ;
这样我们就完成了定义两个Custom,NoneSet的工具栏定义,使用方法Toolbar=后面名称按成自定义的就可以了
(字节数 : 1430)
