當我創建的方法與實際控制人的路線,通用控制器說: 「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)
{
}
}
基地
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