ÐÂÊÖ¸ú×ÅѧAsp.net MVC2 Controller
ÉÏ´ÎÎÒÃÇ˵µ½ÁË route ·ÓɵŦÄÜ,Õû¸ömvcÔËÐйý³Ì:
Route(·ÓÉ) --> Controller(¿ØÖÆÆ÷)-->action(·½·¨)
Õâ´ÎÎÒÃÇҪ˵µÄ¾ÍÊÇ controller ¿ØÖÆÆ÷ ºÍ action£º
¿ØÖÆÆ÷µÄ×÷ÓþÍÊÇ£ºµ±Ò»¸ö Request À´µÄʱºò£¬Ê×ÏÈRoute ½âÎö ÕÒµ½ÁË ¶ÔÓ¦ ¿ØÖÆÆ÷£¬¿ØÖÆÆ÷ÔÙ¸ù¾Ý action ¾ö¶¨¸øÎÒÃÇ·µ»ØʲôÑùµÄÄÚÈÝ¡£È磺
´úÂë
public class MyControllerController : Controller
{
public ActionResult MyAction(DateTime dt)
{
ContentResult cr = new ContentResult();
cr.Content = "MyController's MyAction is Workded!" + dt.ToString("yyyyÄêMMÔÂddÈÕ");
return cr;
}
public void MyTest()
{
Response.Write("hhhh");
}
}
Ê×ÏÈ£º ¿ØÖÆÆ÷Àà ±ØÐë¼Ì³Ð Controller£¬Õâ¸öÎÒÃÇн¨controller µÄʱºò ¶¼ÒѾ¸øÎÒÃǼ̳кÃÁË£¬ÕâÀïÎÒÃÇÆðÁËÒ»¸öÃû×ֽГMyController”£»
ÕâÀï¿ØÖÆÆ÷ÃüÃû¹æÔò ×îºóÐèÒªÊÇController£¬È磺TestController……
Õâ¸ö¿ØÖÆÆ÷ÀïÃæÎÒÃÇдÁË2¸ö·½·¨£¬Ê×ÏȵÚÒ»¸ö MyAction£¬½ÓÊյIJÎÊýÊÇ DateTimeÐ굀 dt£¬ÕâÀïÎÒÃǵÚÒ»¸ö±Ê¼ÇÒѾ˵µ½ÁËurl ¹æÔòÀïÃæµÄ {dt}²ÎÊý£¬ÕâÀïÎÒÃÇÕâÑù½ÓÊÕµ½ÎÒÃÇurlÀïÃæËù´«µÝµÄ²ÎÊý;·µ»ØÀàÐÍÊÇ ActionResult£¬·µ»ØÀàÐÍÓкü¸ÖÖÈ磺
ViewResult:Ò»°ã³ÊÏÖij¸öaspxÎļþ£¬ÓÉView·½·¨·µ»Ø¡£
RedirectToResult:ʹä¯ÀÀÆ÷Öض¨Ïò£¬ÓÉRedirect·½·¨·µ»Ø¡£
RedirectToRouteResult:Ö±½Ó½»¸øÏÂÒ»¸öAction£¬ÓÉRedirectToAction·½·¨·µ»Ø¡£
ContentResult:ÒÔÎÄ×ÖÐÎʽ·µ»Ø
ÉÏÃæÊdz£Óõļ¸Ö
Ïà¹ØÎĵµ£º
·½·¨
Êý¾ÝÁ¿
ÉúÃüÆÚ
×÷ÓÃÓò
λÖÃ
Application
ÈÎÒâ´óС
Õû¸öÓ¦ÓóÌÐò
ËùÓÐÓû§
·þÎñ¶Ë
Cache
ÈÎÒâ´óС
¸ù¾ÝÐèÒªÉ趨
ËùÓÐÓû§
·þÎñ¶Ë
Cookie
¼òµ¥Êý¾Ý
¸ù¾ÝÐèÒªÉ趨
µ¥¸öÓû§
¿Í»§¶Ë
Session
¼òµ¥Êý¾Ý
Óû§»î¶¯Ê±¼ä+ÑÓ³Ùʱ¼ä(20·ÖÖÓ)
µ¥¸öÓû§
·þÎñ¶Ë
Web.Config
¼«Éٸıä¼òµ¥Êý¾Ý
Ö±µ½¸Ä±äÅä ......
ÀýÒ»£º
+++ ÐÞ¸ÄGlobal.asaxÎļþ£º
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{ }
void Application_End(object sender, EventArgs e)
{ }
void Application_Error(object sender, EventArgs e)
{ }
void ......
+++ ÐÞ¸ÄGlobal.asaxÎļþ£º
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["count"] = 0;
}
void Application_End(object sender, EventArgs e)
{ }
void Application_Error(object sender, EventArgs ......
Äú¿ÉÒÔʹÓÃHTTPÄ£¿é£¬Ò»¸öµ½ASP.NET HttpApplicationStateÀàµÄÀ©Õ¹£¬ÔÚGlobal.asax±àд´úÂëÇ¿ÖÆASP.NETÔÚÿһ¸öÒ³ÃæÇëÇóʱ×Ô¶¯×¢ÈëÒÀÀµµÄ¶ÔÏ󣬾ÍÏñÔÚASP.NET Web´°ÌåÓ¦ÓóÌÐòÖÐÌÖÂÛµÄÒ»Ñù.
ÏÂÁз½·¨ÏÔʾÁËÒ»¸öºÏÊʵķ½·¨Äܹ»»ñÈ¡PreRequestHandlerExecuteʼþ½«Ëü×Ô¼º×¢Èëµ½ASP.NE ......
ÈçÓÐÒ³ÃæAdmin£¬ÔòÔÚÆäcsÎļþÖÐдÈçÏ´úÂ룺
protected void Page_Load(object sender, EventArgs e)
{
Response.AddHeader("Cache-Control", "no-cache");
Response.Expires = -1;
Response.Cache.SetNoStore();
Response.AddHeader("Pragma", "no-cache");
Response ......