在普通课上,我需要从 HttpContext
中阅读以下内容:
HttpActionContext.ActionDescriptor.GetCustomAttributes<type>()
获得,但这里我没有 HttpActionContext
- 我只有 HttpContext
)actionContext.ActionArguments["paramName"]
,但同样 - 我只有一个 HttpContext
)它不是 Action 过滤器,也不是 Controller 类。但是,我可以访问
HttpContext
.
最佳答案
From asp.net core 3.0 https://stackoverflow.com/a/60602828/10612695
public async Task Invoke(HttpContext context)
{
// Get the enpoint which is executing (asp.net core 3.0 only)
var executingEnpoint = context.GetEndpoint();
// Get attributes on the executing action method and it's defining controller class
var attributes = executingEnpoint.Metadata.OfType<MyCustomAttribute>();
await next(context);
// Get the enpoint which was executed (asp.net core 2.2 possible after call to await next(context))
var executingEnpoint2 = context.GetEndpoint();
// Get attributes on the executing action method and it's defining controller class
var attributes2 = executingEnpoint.Metadata.OfType<MyCustomAttribute>();
}
关于asp.net-web-api - 网页 API : how to read action attribute and parameters from HttpContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50747797/