0

我正在扩展ActionResult课程。在ExecuteResult方法中,我想检查操作是 aGET还是 aPOST但是类中似乎没有属性ControllerContext可以让我这样做。有人知道如何从 a 检查请求类型ControllerContext吗?

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

    DoOtherStuff();
}
4

2 回答 2

2

您可以使用

context.HttpContext.Request.HttpMethod

http://msdn.microsoft.com/en-us/library/system.web.httprequest.httpmethod%28v=vs.100%29.aspx#Y0

于 2012-06-28T15:07:59.393 回答
0

试试这个:

    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)
        {

        }
    }
于 2012-06-28T15:28:41.320 回答