简体   繁体   中英

Getting request type from ActionResult

I am extending the ActionResult class. In the ExecuteResult method I want to check if the action was a GET or a POST however there doesn't seem property in the ControllerContext class that will let me do that. Does anybody know how to check the request type from a ControllerContext ?

public override void ExecuteResult(ControllerContext context)
{
    //See if the request was POST
    if (context.HttpContext.Request.?)
    {
        DoStuff();
    }

    DoOtherStuff();
}

try this:

    public HttpVerbs RequestHttpVerb(ControllerContext context)
    {
        return (HttpVerbs)Enum.Parse(typeof(HttpVerbs), context.HttpContext.Request.HttpMethod, true);
    }

    public override void ExecuteResult(ControllerContext context)
    {
        if (this.RequestHttpVerb(context) == HttpVerbs.Post)
        {

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM