に一致する私は、私は二つのコントローラを使用したWeb APIプロジェクトを使用しています:属性ルートが要求されたURL
、第1のコントローラは、以下のようなものです:
public class SmartlingController : BaseApiController
{
[Route("api/smartling/ProcessSmartlingTranslation")]
[VersionedRoute("", 1)]
[ResponseType(typeof(HttpResponseMessage))]
[HttpPost]
public IHttpActionResult ProcessSmartlingTranslation(HttpRequestMessage request)
{
//some business logic
}
}
第二コントローラ:
public class CommentsController : BaseApiController
{
[Route("api/comments/GetAndPostBlogComments")]
[VersionedRoute("", 1)]
[ResponseType(typeof(HttpResponseMessage))]
[HttpPost]
public IHttpActionResult GetAndPostBlogComments([FromBody] BlogAndStoryComment comment)
{
//some business logic
}
[Route("api/comments/GetAndPostStoryComments")]
[VersionedRoute("", 1)]
[ResponseType(typeof(HttpResponseMessage))]
[HttpPost]
public IHttpActionResult GetAndPostStoryComments([FromBody] BlogAndStoryComment comment)
{
//some business logic
}
}
以下はwebapiの登録方法です:
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
"DefaultApi",
"api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional }
);
var f = new FormUrlEncodedMediaTypeFormatter();
f.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
f.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/x-www-form-urlencoded"));
config.Formatters.Add(f);
var enableCorsAttribute = new EnableCorsAttribute("*",
"Origin, Content-Type, Accept",
"GET, PUT, POST, DELETE, OPTIONS");
config.EnableCors(enableCorsAttribute);
}
私のコードはここで間違っていますが、どうすればこの問題を解決できますか?
'[VersionedRoute(" "、1)]'これが問題です。それをテストするには、上記のアクションから属性を削除し、競合を解決する必要があります。 – Nkosi