문제웹 API. 내가 실제 컨트롤러의 경로와 방법을 만들 때 속성,
라우팅과 일반 컨트롤러 말 : "API/국가/뭔가"... 내가 수행
을 위의 요청에 따라 코드가 실행되어 & 데이터가 반환됩니다.
하지만베이스 컨트롤러에서 내 경로로 전화를 걸 때. E.G : "api/country/code/123"
404 오류가 발생합니다.
질문
라우팅 속성의 사용을 만드는 동안 일반적인 경로를 구현하는 방법에 대한 어떤 생각?
특정 컨트롤러
[RoutePrefix("Country")]
public class CountryController : MasterDataControllerBase<Country, CountryDto>
{
public CountryController(
IGenericRepository<Country> repository,
IMappingService mapper,
ISecurityService security) : base(repository, mapper, security)
{
}
}
기지 Route
속성의 상속을 지원하지 않는 웹 API에 라우팅
public class MasterDataControllerBase<TEntity, TEntityDto> : ControllerBase
where TEntity : class, ICodedEntity, new()
where TEntityDto : class, new()
{
private readonly IMappingService mapper;
private readonly IGenericRepository<TEntity> repository;
private readonly ISecurityService security;
public MasterDataControllerBase(IGenericRepository<TEntity> repository, IMappingService mapper, ISecurityService security)
{
this.security = security;
this.mapper = mapper;
this.repository = repository;
}
[Route("code/{code}")]
public TEntityDto Get(string code)
{
this.security.Enforce(AccessRight.CanAccessMasterData);
var result = this.repository.FindOne(o => o.Code == code);
return this.mapper.Map<TEntity, TEntityDto>(result);
}
}
가능한 중복 http://stackoverflow.com/questions/19989023/net-webapi-attribute ... 상속 아니라고 디자인 결정이었다 설명 -routing-and-inheritance/24969829 # 24969829 – Dejan