andrewlocatelliwoodcock

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.

Example:

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: andrewlocatelliwoodcock.com/2012/01/26/how-to-distinguish-http-post-action-methods-at-runtime-checking-httpcontext-server-variables/ […]…

    My Homepage

    January 29, 2012 at 17:16


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: