Getting request type from ActionResult
-
17-06-2021 - |
Pregunta
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();
}
Solución
you can use
context.HttpContext.Request.HttpMethod
http://msdn.microsoft.com/en-us/library/system.web.httprequest.httpmethod%28v=vs.100%29.aspx#Y0
Otros consejos
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)
{
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow