ASP.NET MVC ÈëÃÅ
ÓÐʱºòÄãÏëÔÚµ÷ÓÃaction·½·¨Ö®Ç°»òÕßaction·½·¨Ö®ºó´¦ÀíһЩÂß¼£¬ÎªÁËÖ§³ÖÕâ¸ö£¬ASP.NET MVCÔÊÐíÄã´´½¨action¹ýÂËÆ÷¡£Action¹ýÂËÆ÷ÊÇ×Ô¶¨ÒåµÄAttributes£¬ÓÃÀ´±ê¼ÇÌí¼ÓAction·½·¨Ö®Ç°»òÕßAction·½·¨Ö®ºóµÄÐÐΪµ½¿ØÖÆÆ÷ÀàÖеÄAction·½·¨ÖС£
һЩ¿ÉÄÜÓõ½Action¹ýÂËÆ÷µÄµØ·½ÓУº
ÈÕÖ¾,Òì³£´¦Àí
Éí·ÝÑéÖ¤ºÍÊÚȨ £ ÏÞÖÆÓû§µÄ·ÃÎÊ
Êä³ö»º´æ £ ±£´æÒ»¸öActionµÄ½á¹û
ÍøÂçÅÀ³æµÄ¹ýÂË
±¾µØ»¯
¶¯Ì¬Action £ ½«Ò»¸öAction×¢Èëµ½¿ØÖÆÆ÷ÖÐ
ASP.NET MVCΪÎÒÃÇÌṩÁËÏÂÃæµÄ¼¸¸öFilter½Ó¿Ú£º
IActionFilter
IAuthorizationFilter
IExceptionFilter
IResultFilter
ҪʵÏÖÒ»¸öFilter£¬ÎÒÃÇÐèÒª¼Ì³Ð×ÔFilterAttributeÀàͬʱʵÏÖÉÏÃæµÄÒ»¸ö»ò¼¸¸ö½Ó¿Ú£º
public class MyFilter : FilterAttribute, IActionFilter, IResultFilter
{
}
Õ⼸¸ö½Ó¿ÚÌṩµÄ·½·¨ÈçÏ£º
ÉÏͼµÄ·½·¨ºÍFilter½Ó¿Ú¶ÔÓ¦µÄ·½·¨°´Ãû³Æ¶ÔºÅÈë×ù¾Í¿ÉÒÔ¡£
IActionFilter½Ó¿ÚÓÐÁ½¸ö·½·¨£º
ÆäÖÐOnActionExecutingÔÚÖ´ÐÐAction·½·¨Ö®Ç°»á±»µ÷Óã¬OnActionExecuted»áÔÚAction·½·¨Ö´Ðкóµ÷Óá£×¢ÒâËûÃǵIJÎÊý·Ö±ðÊÇActionExecutingContextºÍActionExecutedContext¡£
ActionExecutedContextÀà°üº¬Ò»¸ö CanceledµÄÊôÐÔ£¬ÔÊÐíÄãÈ¡Ïûµ±Ç°µÄAction(ÔõôÔÀ´ÔÚP3ÖÐÊÇÔÚActionExecutingContextµÄCanceledÊôÐÔÔÚP5ÖÐûÓÐÁËÄØ£¿ÉñÆæ.ÄÇôÔÚOnActionExecutingµÄʱºòÔõôȡÏûÒ»¸öActionÄØ£¿)¡£
FilterExcutedContext Àà°üº¬Ò»¸öExceptionÊôÐÔºÍÒ»¸öExceptionHandledÊôÐÔ¡£Èç¹ûExceptionÊôÐÔΪnull£¬ÔòûÓÐÒì³£ÔÚaction stackÖУ¬±íÃ÷Action·½·¨ÔËÐв¢Ã»Óз¢Éú´íÎó¡£·´Ö®ÔòΪ³öÏÖÒì³£¡£Èç¹û½«ExceptionHandledÊôÐÔÉèÖÃΪtrueÔò±íÃ÷ÔÚÕâ¸öFilterÖÐÒѾ´¦ÀíÁËÒì³£¡£
IResultFilter½Ó¿ÚÒ²ÌṩÁËÁ½¸ö·½·¨£º
ËûÃÇ·Ö±ðÔÚAction·µ»Ø½á¹û(ÀýÈçreturn View();)֮ǰºÍÖ®ºóÖ´ÐС£ºÍIActionFilter²î²»¶à¾Í²»¶à˵ÁË¡£
IAuthorizationFilterÊÇÒ»¸öÓÃÓÚÉí·ÝÑéÖ¤µÄFilter¡£Ö»ÌṩÁËÒ»¸övoid OnAuthorization(AuthorizationContext filterContext)·½·¨¡£
IExceptionFilter»áÔÚ³öÏÖÒì³£µÄʱºòµ÷Óã¬Ò²ÊÇÖ» Ìṩһ¸övoid OnException(ExceptionContext filterContext)µÄ·½·¨£»
ÕâЩFilter¿ÉÒÔ±»Ó¦ÓÃÔÚÀà»òÕß·½·¨ÉÏ£¬ÏÂÃæÎÒÃÇÀ´¿´Ò»ÏÂËûÃǵÄÖ´ÐÐ˳Ðò¡£Ê×ÏÈÎÒÃÇдһ¸öBaseController²¢¼ÓÉÏÁ½¸öFilter£º
[MyFilter2(Target =&nb
Ïà¹ØÎĵµ£º
//´´½¨
HttpCookie cookie = new HttpCookie("user","111");//´´½¨Cookie
cookie Expires = DateTime.Now.Add(15);//ÉèÖùýÆÚʱ¼ä
Response.Cookies.Add(cookie);//´æÈë¿Í»§¶Ë
ÎÒÃÇÈ¡³öCookieÖµÒ²ºÜ¼òµ¥
string value = Request.Cookies["user"].value;
ÓÐʱºòÎÒÃÇÏëÔÚÒ»¸öCookieÖд¢´æ¶à¸öÐÅÏ¢£¬ÄÇÒ ......
ʲôÊÇMVCģʽ
MVC£¨Model-View-Controller£¬Ä£ÐÍ—ÊÓͼ—¿ØÖÆÆ÷ģʽ£©ÓÃÓÚ±íʾһÖÖÈí¼þ¼Ü¹¹Ä£Ê½¡£Ëü°ÑÈí¼þϵͳ·ÖΪÈý¸ö»ù±¾²¿·Ö£ºÄ£ÐÍ£¨Model£©£¬ÊÓͼ£¨View£©ºÍ¿ØÖÆÆ÷£¨Controller£©¡£
ÄÇôMVCģʽºÍÎÒÃÇÊìϤµÄWebFormģʽÓÐʲô²»Í¬ÄØ£¿ËûµÄ¸÷¸ö²¿·ÖÓÖÊÇÔõÑù·Ö¹¤µÄÄØ£¿
ÎÒÃÇÏÈÀ´¿´Ò»ÏÂÆÕͨµÄWebFormģʽÏ£ ......
ÓÃÕýÔò±í´ïʽÏÞÖÆÖ»ÄÜÊäÈëÖÐÎÄ£º
¡¡¡¡1.ÓÃÕýÔò±í´ïʽÏÞÖÆÖ»ÄÜÊäÈëÈ«½Ç×Ö·û£º
¡¡¡¡2.ÓÃÕýÔò±í´ïʽÏÞÖÆÖ»ÄÜÊäÈëÊý×Ö£º
¡¡¡¡3.ÓÃÕýÔò±í´ïʽÏÞÖÆÖ»ÄÜÊäÈëÊý×ÖºÍÓ¢ÎÄ£º
¡¡¡¡4.¼ÆËã×Ö·û´®µÄ³¤¶È(Ò»¸öË«×Ö½Ú×Ö·û³¤¶È¼Æ2£¬ASCII×Ö·û¼Æ1)
¡¡¡¡String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa"). ......
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// javascriptµ¯³ö´°¿Ú·â×°Àà
/// </summary>
public static class JSCommon
......
Ê×ÏÈÏÈÖØÎÂһϹØÓÚb/sģʽµÄÕû¸öÇëÇó¹ý³Ì:
¿Í»§¶Ëͨ¹ýÔÚä¯ÀÀÆ÷µÄµØÖ·À¸ÇÃÈëµØÖ·À´·¢ËÍÇëÇóµ½·þÎñÆ÷¶Ë -> ·þÎñÆ÷½ÓÊÕµ½ÇëÇóÖ®ºó£¬·¢¸øÏàÓ¦µÄ·þÎñÆ÷¶ËÒ³Ã棨Ҳ¾ÍÊǽű¾£©À´Ö´ÐУ¬½Å±¾²úÉú¿Í»§¶ËµÄÏìÓ¦£¬·¢Ëͻؿͻ§¶Ë -> ¿Í»§¶Ëä¯ÀÀÆ÷½ÓÊÕµ½·þÎñÆ÷´«»ØµÄÏìÓ¦£¬¶ÔHtml½øÐ ......