ASP.NET MVC 4 - AcceptVerbsttribute

From this day forward, I'll pick my think up, in my loveless english,I plan to summary something about ASP.NET MVC 4 and some experience involve just my personal experience , in particular about the namespace belong ASP.NET MVC ,the core system.web.mvc  and system.web.ajax ,system.web.mvc.Async,last include the new engine the razor namespace .intend as long as I have time I always write some to the blog .at once you look up just look i'm not professional .everybody always do . the microsof support a series of class .interface , we just learn it and make it to us solution the problem . don't pray someday you can change the world and always have a nice day .
since asp.net mvc 4 released .microsoft open the source .and this day .i'll learn the first class about namaspace system.web.mvc 

in general , i analysis this just follow  step about:

1,the class who inherit it and we can use it to do what ?

2,how to use it to solution our problem ?

3,some ruse about this class 

4,the member of this class ,the method , field , or delegate or some method override his base class and so on .

5,have any design pattern about this class ?  

6,what time can we use it ? why we use it ?

7,some example ! aka everybody love example .

thanks for MSDN and make reference to MSDN  http://msdn.microsoft.com

 

 

     AcceptVerbAttribute Class 

Like the classname ,It means what kind of way be allowed when user request the controller action will executed .

1.the class is inherit from the ActionMethodSelectorAttribute, dont care about this class just know it is cheked the user request is validate .as far as how to meke it  who care . we just need to learn how to use it . in additional i think it maybe cut the method to some sub method you write core method just is a para. 

 also like the classname ,mybe we can use it to solution some login or register problem .and some membership .

2.this attribute is the level of method and just the method it is seald  means you can't use : to your personal class and in my opinion it just enough to solution some general problem .you can use it superpose the method , it have an internal static string [] not an enum .include some general request way like GET POST PUT DELETE  HEAD  PATCH  OPTIONS  to be honest . i just use get or post .even i didn't know another way .who can teach me :)

3.every method look like the back office method is an hook . so you can use this to do anything you like .as long as it in the api .

4.it have two constructor ones is required and unsure how many length of string type array and another one is : previous i  just like the proxy patten .

and it have an array type of string . we haved talk about it in 2 . then it include an override method named isValidForRequest the method is required two parameter one is the controllercontenxt and second is methodinfo  in surface  it's so reasonable ,if is you .you also need the two parameter to decide allow? and witch allow . in deep  it use an enumerable method it have two incomeing parmeter one is what kind of about the request way string .and another one is to ignore the case . so wehave this .we can put it to the mvc core let it .i meaning some low-rise .to achieve this .

5. i just say like proxy patten in this class .so you can teach me .

6.in order to achieve some limit about user request , i think it can save time to let us do something about the business logic .

7 some snippt  

      // [AttributeUsage(AttributeTargets.Method,AllowMultiple = false, Inherited = true)]

public class HomeController : Controller
        {
        //
        
// GET: /Home/
        [AcceptVerbs(HttpVerbs.Get)]
        public string Index(int id)
        {
            Response.Write("this is Get");
            return "Get";
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public string Index()
        {
            Response.Write("this is Post");
            return "Post";下午9:18:32
        }
}

if you copy this snip to your test demo . you can see it in the browser page have an error .

 

  beacuse the default request way is  GET  so if you  put Home/Index/(anynumeral)

 

so as you can see .this is the Class Demo .you can let you imagine to the universe . i just take a little benift of your parents .so  say u late . 

转载于:https://www.cnblogs.com/nikain/p/3145020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值