ASP.net MVCÓëRESTful ROA»¹ÊÇÓеãÇø±ðµÄ
ÒÔblogϵͳΪÀý£¬Ò»¸ö¼òµ¥µÄblogϵͳģÐÍ°üÀ¨£º
1.·¢±íһƪеÄblog
2.ÏÔʾһƪblog
3.ÐÞ¸Äһƪblog
4.ɾ³ýһƪblog
ASP.net MVC»áÊÇÕâÑùµÄURL¹æ»®£º
*. http://www.gaotianpu.com/blog/create,´´½¨
get·½·¨¸øÓû§Õ¹Ê¾Ò»¸öhtml±íµ¥,¹©Óû§Ìá½»Êý¾Ý
post·½·¨½ÓÊÜÓû§Ìá½»µÄÊý¾Ý£¬²åÈëµ½db
*. http://www.gaotianpu.com/blog/123,»ñȡչʾblog idΪ123µÄblog
*. http://www.gaotianpu.com/blog/Edit/123,ÐÞ¸Ä
get,չʾ±à¼ÓõÄhtml±íµ¥
post,½ÓÊܱ༺óµÄÊý¾Ý
*. http://www.gaotianpu.com/blog/Delete/123,ɾ³ý
ͨ³£¶¼ÓÃget·½·¨Ö´ÐÐ.
MVC»áÔÚurlÖÐÏÔʾµÄ¸ø³ö×ÊÔ´µÄ²Ù×÷·½·¨,ÁíÍ⣬MVC»¹Òª¸ºÔðÊä³öÓû§½»»¥½çÃæ¡£
¶øRESTful ROA˼ÏëÔò»áÕâÑù¹æ»®URL
http://www.gaotianpu.com/blog/123
ʹÓÃHttp MethodÀ´Çø·ÖÕë¶Ô¸Ã×ÊÔ´µÄ²Ù×÷£º
*. get,»ñÈ¡id=123µÄblog
*. put,ÐÞ¸Äid=123µÄblog
*. delete,ɾ³ýid=123µÄblog
http://www.gaotianpu.com/blog/,
*. post£¬±íʾ´´½¨Ò»ÐÂblog¡£
(ΪÁ˱£Ö¤ÃݵȲÙ×÷£¬¼´·ÀÖ¹Öظ´Ìá½»ÏàͬÄÚÈÝ£¬post·½·¨»á¸½¼ÓÒ»¸öguid²ÎÊý£¬ÈôÁ½´ÎÌá½»µÄguid²ÎÊýÏàͬ£¬Ôò±íʾÖظ´Ìá½»£¬ºóÒ»´ÎÌá½»µÄ¸²¸ÇÇ°Ò»´Î¡£)
*. get ,¼ÓÔØblogÁбí.
µ±È»£¬ÆÕͨµÄweb formÊDz»Ö§³Öput,delete,head,optionµÈÕâÑùµÄÌØÊâhttp·½·¨µÄ£¬µ«¿ÉÒÔÔÚpost»ù´¡ÉÏÄ£ÄâµÃµ½.
Ϊʲô»áÓÐÕâÑùµÄÇø±ðÄØ£¿
RESTful Web Service,¾ÍÊÇÓÃÀ´Ìṩweb·þÎñµÄ£¬ºÍasp.net mvc²»Í¬£¬Ëü¿ÉÒÔ²»¿¼ÂÇÓû§½»»¥½çÃæ¡£
±ÈÈç˵,µ±´´½¨¡¢ÐÞ¸Äһƪblogʱ£¬asp.net mvcͬһurlÒªÖ§³Ö2ÖÖ·½·¨:get,¸øÓû§Ò»¸ö¿É²Ù×÷µÄ½çÃ棬post½ÓÊÜÓû§Ìá½»µÄÊý¾Ý£¬
¶ørestÔò²»Óÿ¼ÂǸøÓû§ÕâÑùµÄ²Ù×÷½çÃ棬²Ù×÷½çÃæÒªÓÉ¿Í»§¶ËÍê³É¡£
¶þÕß²»´æÔÚËÌ滻ˣ¬Ë±È˸üºÃµÄÎÊÌâ¡£
¼òµ¥±È½ÏÁËһϣ¬¸öÈ˾õµÃʹÓÃASP.net MVC À´ÊµÏÖRESTful webservice»¹ÊÇÓÐЩǣǿµÄ£¬²»ÖªµÀWCFÊÇÈçºÎ´¦ÀíRESTfull web serivceµÄ £¿
×îа汾£ºhttp://www.gaotianpu.com/blog/detail/248
Ïà¹ØÎĵµ£º
ÎÒÃÇÔÚÊ״β¿ÊðmvcµÄÏîĿʱͨ³£»áÓöµ½Ò»µãÎÊÌâ¡£M$ÒѾÔÚGlobal.asax.csÎļþÖаüº¬ÁËÕâÁ½¾ä×¢Ê͵ÄÌáʾ¡£
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
µ«ÊÇÎÒÃÇ·ÃÎÊÕâ¸öÍøÖ·¿´µ½ÉÏÃæµÄÎÄÕ¶Ôiis5.1(win ......
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1ÊÇupdatepanelµÄid
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1ÊÇupdatepanelµÄid
......
ÔÚ2003ϵͳÏÂ,°´ÕÕÔÚIIS6ÖÐÍøÕ¾ÓÒ¼üÊôÐÔ£Ö÷Ŀ¼£ÅäÖãÔÚͨÅä·ûÓ¦ÓóÌÐòÓ³É䣲åÈëÉèÖÃÌí¼ÓͳÅä·û,¿ÉÖ´ÐÐÎļþÑ¡ÔñC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll¡¡×¢Òâ“È·ÈÏÎļþÊÇ·ñ´æÔÚ”Õâ¸öÑ¡ÏҪѡÉÏ
2 Õ¾µãÖÐÒýÈëUrlRewrting.dll
3 Web.configÅäÖÃÐÞ¸ÄÈçÏ£º
<RewriterConfig& ......
¹ã¶«ÄϺ£Êй«°²¾Ö¼ÆËã»ú°²È«¼à²ì¹ÉÓ÷¿
ASP.NETÊÇ΢ÈíÍƳöµÄÏÂÒ»´úWEB¿ª·¢¹¤¾ß£¬ÆäÇ¿´óµÄ¹¦ÄÜÁ¢¼´ÎüÒýÁËÒ»´óÅúWEB¿ª·¢ÕßͶÈëËüµÄÃÒÏ¡£ÏÖÔÚ£¬ÎÒÃÇÀ´¿´¿´ASP.NETµÄÑéÖ¤¿Ø¼þ£¬¸ÐÊÜASP.NETµÄÇ¿´ó¹¦ÄÜͬʱ·½±ãÎÒÃÇÏÖÔÚµÄWEB¿ª·¢¡£
WEB¿ª·¢ÕßÌرðÊÇASP¿ª·¢Õߣ¬Ò»Ö±¶ÔÊý¾ÝÑéÖ¤±È½ÏÄջ𣬵±ÄãºÃ²»ÈÝÒ×д³öÊý¾ ......