Thoughts on Software

How to distinguish HTTP POST action methods at runtime: Checking HTTPContext Server Variables

leave a comment »

Following on from my last post, there is an alternative method for distinguishing whether we are dealing with an HTTP POST. Before, I suggested checking the ActionDecriptor to see whether there was an HttpPost attribute applied. An alternative to this is to check the ControllerContext for the REQUEST_METHOD server variable. If this is “POST”, then this is an HTTP POST.


public static bool IsHttpPost(ControllerContext context) 
    return context.RequestContext.HttpContext.Request.ServerVariables.Get("REQUEST_METHOD").ToUpper() == "POST"; 


Written by andrewlocatelliwoodcock

January 26, 2012 at 18:03

No Responses Yet

Subscribe to comments with RSS.

  1. … [Trackback]…

    […] Read More here: […]…

    My Homepage

    January 29, 2012 at 17:16

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: