ASP.NetÖÐ×Ô¶¨ÒåHttp´¦Àí¼°Ó¦ÓÃÖ®HttpModuleƪ
HttpHandlerʵÏÖÁËÀàËÆÓÚISAPI ExtentionµÄ¹¦ÄÜ£¬Ëû´¦ÀíÇëÇó(Request)µÄÐÅÏ¢ºÍ·¢ËÍÏìÓ¦(Response)¡£HttpHandler¹¦ÄܵÄʵÏÖͨ¹ýʵÏÖIHttpHandler½Ó¿ÚÀ´´ïµ½¡£¶øHttpModuleʵÏÖÁËÀàËÆÓÚISAPI FilterµÄ¹¦ÄÜ¡£
HttpModuleµÄʵÏÖ
HttpModulesʵÏÖÁËÀàËÆÓÚISAPI FilterµÄ¹¦ÄÜ£¬ÔÚ¿ª·¢ÉÏ£¬Í¨³£ÐèÒª¾¹ýÒÔϲ½Ö裺
±àдһ¸öÀ࣬ʵÏÖIhttpModule½Ó¿Ú
ʵÏÖInit ·½·¨£¬²¢ÇÒ×¢²áÐèÒªµÄ·½·¨
ʵÏÖ×¢²áµÄ·½·¨
ʵÏÖDispose·½·¨£¬Èç¹ûÐèÒªÊÖ¹¤ÎªÀà×öһЩÇå³ý¹¤×÷£¬¿ÉÒÔÌí¼ÓDispose·½·¨µÄʵÏÖ£¬µ«Õâ²»ÊDZØÐèµÄ£¬Í¨³£¿ÉÒÔ²»ÎªDispose·½·¨Ìí¼ÓÈκδúÂë¡£
ÔÚWeb.configÎļþÖУ¬×¢²áÄú±àдµÄÀà
ÏÂÃæÊÇÒ»¸öHttpModulesµÄʾÀý£¬ÔÚÕâ¸öʾÀýÖУ¬Ö»ÊǼòµ¥µÄ×¢²áÁËHttpApplication µÄBeginRequest ºÍ EndRequestʼþ£¬²¢ÇÒͨ¹ýÕâЩʼþµÄʵÏÖ·½·¨£¬½«Ïà¹ØµÄÐÅÏ¢´òÓ¡³öÀ´¡£
Àý1£º
¡¡ using System;
using System.Web;
namespace MyModule{
public class MyModule : IHttpModule {
public void Init(HttpApplication application) {
application.BeginRequest += (new
EventHandler(this.Application_BeginRequest));
application.EndRequest += (new
EventHandler(this.Application_EndRequest));
}
private void Application_BeginRequest(Object source, EventArgs e) {
HttpApplication Application = (HttpApplication)source;
HttpResponse Response=Application.Context.Response;
Response.Write("<h1>Beginning of Request</h1><hr>");
}
private void Application_EndRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpResponse Response=Application.Context.Response;
Response.Write("<h1>End of Request</h1><hr>");
}
public void Dispose() { }
}
}
³ÌÐòµÄ¿ªÊ¼ÒýÓÃÁËÈçÏÂÃû³Æ¿Õ¼ä£º
using System;
using System.Web;
ÒòΪHttpApplication¡¢HttpContext¡¢HttpResponseµÈÀàÔÚSystem.WebÖж¨Ò壬Òò´Ë£¬System.WebÃû³Æ¿Õ¼äÊDZØÐëÒýÓõġ£
MyModuleÀàʵÏÖÁËIhttpModule½Ó¿Ú¡£ÔÚInit·½·¨ÖУ¬Ö¸Ã÷ÁËʵÏÖBeginRequest ºÍEndRequest ʼþµÄ·½·¨¡£ÔÚÕâÁ½¸ö·½·¨ÖУ¬Ö»ÊǼòµ¥µÄ·Ö±ð´òÓ¡ÁËһЩÐÅÏ¢¡£
ÏÂÃ棬ÔÚWeb.configÎļþÖÐ×¢²áÕâ¸öÀ࣬¾Í¿ÉÒÔʹÓÃÕâ¸öHttpModuleÁË£¬×¢²áµÄ·½·¨ÈçÏ£º
<configuration>
<system.web>
Ïà¹ØÎĵµ£º
Ò»¡¢SqlDataReadºÍDatasetµÄÑ¡Ôñ
SqldatareadÓŵ㣺¶ÁÈ¡Êý¾Ý·Ç³£¿ì¡£Èç¹û¶Ô·µ»ØµÄÊý¾Ý²»Ðè×ö´óÁ¿´¦ÀíµÄÇé¿öÏ£¬½¨ÒéʹÓÃSqlDataReader£¬ÆäÐÔÄÜÒª±ÈdatsetºÃºÜ¶à¡£È±µã£ºÖ±µ½Êý¾Ý¶ÁÍê²Å¿ÉcloseµôÓÚÊý¾Ý¿âµÄÁ¬½Ó
(SqlDataReader ¶ÁÊý¾ÝÊÇ¿ìËÙÏòÇ°µÄ¡£SqlDataReader ÀàÌṩÁËÒ»ÖÖ¶ÁÈ¡´Ó SQL Server
Êý¾Ý¿â¼ìË÷µÄÖ»½øÊý¾ÝÁ÷µ ......
1.ǰ̨ҳÃæÒ»°ã²»ÓÃgridview datalist treeview updatepanel µÈ¿Ø¼þ£¬ÒòΪËûÃÇ»áÉú³ÉºÜ¶àÎÒ²»ÏëÒªµÄ´úÂë¡£¶øÇÒǶÌ×Ò»´ó¶Ñtable
2.ÓÃrepeater+div+css+ul liÒѾ×ã¹»ÎÒ×öºÜ¶à¶«Î÷ÁË¡£
3.·¢²¼ºóµÄÒ³Ã棬¿ÉÒÔ°ÑһЩ¿ÕÐкͻ»ÐÐ ºÍһЩ²»±ØÒªµÄ¿Õ¸ñÈ¥µô£¬¾¡Á¿¼õÉÙaspxÒ³ÃæµÄÈÝÁ¿¡£Ìá¸ß¼ÓÔØËٶȡ£
4.ÔÚÒ³ÃæµÄtitleдÉϱ¾Ò³ÄÚÈÝ ......
1. ´ò¿ªÐµĴ°¿Ú²¢´«ËͲÎÊý£º
¡¡¡¡´«ËͲÎÊý£º
response.write("£¼script£¾window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)£¼/script£¾")
¡¡¡¡½ÓÊÕ²ÎÊý£º
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
¡¡¡¡2.Ϊ°´Å¥Ìí¼Ó¶Ô»°¿ò
Button1 ......
1¡¢Ë«»÷Ò»¸öÊý¾ÝÔ´¿Ø¼þ£¬½«Òª´æ´¢profileµÄÊý¾Ý¿â×÷ΪÊý¾ÝÔ´¼ÓÈë¿Ø¼þ£¨Õâ¸ö²½ÖèûʲôÓã¬Ö»ÊÇΪÁË·½±ã´ó¼ÒÓÿؼþ½¨Á¢Á¬½Ó£¬ÕâÑù²»ÈÝÒ׳ö´í£©£¬½¨Á¢ºÃÖ®ºó½«designÒ³ÃæµÄÊý¾ÝÔ´¿Ø¼þɾ³ý£¬Äã»á·¢ÏÖÔÚweb.configÀﻹÊÇÓÐÒ»ÌõÁ¬½ÓÓï¾ä£¬²»ÒªÉ¾³ý£¬ÎÒÃÇÏÂÃ潫Óõ½Ëü£¬È磺 <connectionStrings>
<add ......