C# 路由的自定义属性
我想为路线中的参数创建一个自定义属性。我不能使用“ParameterBindingAttribute” 在“dosomething”之前,我想验证参数myVar 如何做到这一点C# 路由的自定义属性,c#,asp.net-web-api2,asp.net-web-api-routing,C#,Asp.net Web Api2,Asp.net Web Api Routing,我想为路线中的参数创建一个自定义属性。我不能使用“ParameterBindingAttribute” 在“dosomething”之前,我想验证参数myVar 如何做到这一点 [Route("{myVar}/TOTO")] public IHttpActionResult Get([myAttribute]int myVar) { //Do something } 谢谢您可以编写一个操作过滤器来检查这些值 [VerifyMyVar] public IHttpActionResult
[Route("{myVar}/TOTO")]
public IHttpActionResult Get([myAttribute]int myVar)
{
//Do something
}
谢谢您可以编写一个操作过滤器来检查这些值
[VerifyMyVar]
public IHttpActionResult Get(int myVar)
{
// TODO
}
public class VerifyMyVar : HttpActionFilterAttribute
{
...
}
如果您想要更具体的验证,您可以让筛选器检查MethodInfo,并对[myAttribute]中的代码执行更具体的操作。请详细说明您的问题,以使其更清楚?