[ת]ASP.NET MVCÒì³£´¦Àí·½°¸(2)
¿ÉÒÔºÜÇå³þµÄ¿´µ½£¬MVCʵ¼ÊÉÏÊÇʹÓøղÅÎÒÃÇÖ¸¶¨µÄViewÃû³Æн¨ÁËÒ»¸öViewResult£¬È»ºó½«Õâ¸öViewResult½»¸øÁË InvokeActionResult·½·¨£¬×îÖÕÏÔʾ¸øÁËÓû§¡£ÔÚÕâ¸ö¹ý³ÌÖУ¬ÐµÄViewResultµÄViewData±»É趨Ϊ HandleErrorInfoÁË£¬Ã»Óн«CreateÉϵÄÊý¾Ý·Å½øViewData£¬¾¡¹ÜÔÚÖ®ºóÏÔʾµÄCreateÊÓͼµÄRequestÀﻹ±£´æ×Å֮ǰ µÄParamsÄÚÈÝ£¬µ«ÊÇÊý¾ÝȴûÓмÓÔØÉÏÈ¥£¬ÎÒҲûÓÐÈ¥É£¬¸Ð¾õÈç¹ûÔÚÕâÀïÖ±½Ó°ÑfilterContext.ControllerÖÐµÄ ViewDataÖ±½Ó×÷ΪеÄViewResultµÄViewDataµÄ»°£¬¿Ï¶¨ÊÇ¿ÉÒÔÏÔʾÌύ֮ǰµÄÊý¾ÝµÄ(ÒòΪÈç¹û½«Òì³£´úÂë°üÔÚ try...catch...ÀïÃæÊÇ¿ÉÒÔÔÚÒì³£ºóÏÔʾ֮ǰÊý¾ÝµÄ)¡£
ÓÚÊÇ×ÔÒÑн¨Ò»¸öExceptionFitler£º
public class CustomHandleErrorAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { filterContext.Controller.ViewData["Exception"] = filterContext.Exception; filterContext.Result = new ViewResult() { ViewName = filterContext.Controller.ControllerContext.RouteData.Values["Action"].ToString(), ViewData = filterContext.Controller.ViewData }; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; } }
ÀàÃûÆðµÄ²»Õ¦µÄ£¬½«¾Í×ÅÓðÉ:)
½«ÔÀ´µÄActionÐÞ¸ÄÈçÏ£º
[HttpPost] [CustomHandleError] public ActionResult Create(string Name) { throw new Exception("oops..."); }Create.csthmlÖмÓÈëÈçÏ´úÂ룺
if (ViewData["Exception"] != null) { var ex = ViewData["Exception"] as Exception; @ex.Message }F5,¹ûÈ»ÔÚÌá½»ºóÓֻص½ÁËÔÀ´ÊÓͼ£¬¶øÇÒ֮ǰÌîдµÄÊý¾Ý¶¼»¹ÔÚ¡£
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- Asp.net MVCÔ´Âë·ÖÎö--Model Validation(Se....
- .Net À¬»ø»ØÊÕ»úÖÆÔÀíºÍËã·¨£¨Ò»£©
- .netʵÌåнâ
- ·ÖÎöASP.NET¶ÁÈ¡XMLÎļþ4ÖÖ·½·¨
- »ñÈ¡ÍøÕ¾ËõÂÔͼ´úÂë
- Asp.net ¸ù¾ÝIPµØÖ·»ñÈ¡¿çÍø¶ÎmacµØÖ·º¯Êý¡¾ËѲء¿
- ¹ýÂËÃô¸Ð¹Ø¼ü×Ö¡£
- Éú³ÉÖ¸¶¨Î»ÊýµÄËæ»ú×Ö·û´®
- ¿Í»§¶Ë»ñÈ¡MACµØÖ·£¬µ½·þÎñÆ÷ÑéÖ¤
- ²½²½ÎªÓª .NETÈý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ