在 OnActionExecuting
方法期间,进行了一些可能导致重定向到主页的处理。
但是在Ajax POST 调用中,这些处理肯定会失败。调用是由 Kendo UI 中的网格进行的,因此我无法控制它们。
因此,如果调用是 GET
和 POST
,我希望此方法以两种不同的方式处理。
我试过了:
[HttpGet]
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Do something
}
[HttpPost]
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Do nothing
}
但它确实有效。
我在 WebFroms 中找不到像 IsPostBack
这样的属性。
最佳答案
ActionExecutingContext
有一个 HttpContext
属性。从那里,您可以获得 Request
属性,该属性具有 HttpMethod
属性
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if(filterContext.HttpContext.Request.HttpMethod == "POST")
{
// Do nothing
}
else
{
//Do Something
}
}
关于c# - 在 OnActionExecuting 期间以不同方式处理 GET 和 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22192431/