모든 컨트롤러에 필수 매개 변수를 추가 할 수 있습니까? RESTful API를 개발하므로 모든 경로에 특별한 "apikey"매개 변수가 필요합니다.AttributeRouting 필수 매개 변수
[HttpPut]
[PUT("create")]
public PostDto Create(string title, string description, string tag, long photo, float lat, float lon, int error)
{
if (description.Length > DescriptionMaxLength)
throw new ApiException(ErrorList.TooLongDescription, string.Format("Description is more than {0}", DescriptionMaxLength));
throw new NotImplementedException();
}
[HttpPost]
[POST("edit/{id:int}")]
public bool Edit(int id, string title, string description, int? photo)
{
if (description.Length > DescriptionMaxLength)
throw new ApiException(ErrorList.TooLongDescription, string.Format("Description is more than {0}", DescriptionMaxLength));
throw new NotImplementedException();
}
[HttpDelete]
[DELETE("delete/{id:int}")]
public bool Delete(int id)
{
if (id < 0)
throw new ApiException(ErrorList.InvalidValue, "id is smaller than 0");
throw new NotImplementedException();
}
하지만 모든 방법에 대해 수동으로하고 싶지는 않습니다.
'apikey'와 같은 필수 매개 변수의 경우 authenticate 메소드에서 BaseController 또는 ActionFilter를 사용하여 유효성을 검사합니다. 나중에 apikey에 대한 액세스가 필요한 경우 항상 존재한다고 가정 할 수 있습니다. 필터가 apikey를 Context.Items 컬렉션이나 원하는 경우 비슷한 것으로 푸시하도록 할 수도 있습니다. –