我在控制器中作为可选参数:
GetPostalCodeLocation(string postalCode, string postalCodeExt, string place = "", string district = "")
如果在URL我没有把它区域工作,但在应用程序中生成此URL:
Url:"http://localhost:62814/Api/Address/PostalCodeLocation?postalCode=2415&postalCodeExt=021&place=&district=Leiria"
我无法控制URL(由平台定义)
可以在路由集 &place= 中忽略吗?谢谢
UPDATE 我有这个动作过滤器
Dictionary logParameters = new Dictionary();
logParameters = new Dictionary();
actionContext.Request.Properties.Add(new KeyValuePair("watch", watch));
actionContext.Request.Properties.Add(new KeyValuePair("action", actionName));
Create integer parameter.
foreach (var param in actionContext.ActionArguments)
{
if (param.Value == null)
{
throw new Exception("Parameter " + param.Key + " cannot be null");
}
{
logParameters.Add(param.Key, param.Value.ToString());
}
}
actionContext.Request.Properties.Add(new KeyValuePair("logParameters", logParameters));
base.OnActionExecuting(actionContext);