0

Web APIコントローラにヘルプページが表示されない場合があります。コントローラの唯一の方法は以下の通りです:asp.net mvc web apiのヘルプページが指定されたルートに入力されていません

GET api/mycontroller?p1={p1}&p2={p2}&p3={p3} 

ヘルプページへの私のコメントの流れのしかしなし:

public HttpResponseMessage Get(string p1,string p2= "blend", string p3 = "blend") 

方法は、署名をヘルプページに反映されます。他のシンプルなコントローラーGet(string id)では、ヘルプページが正常に機能します。

私はWebApiConfig.cs

config.Routes.MapHttpRoute( name: "mycontroller", routeTemplate: "api/mycontroller/{p1}/{p2}/{p3}", defaults: new { p1 = RouteParameter.Optional, p2 = RouteParameter.Optional, p3 = RouteParameter.Optional
} );

に次を追加してみました。しかし、まだヘルプページには、要約、PARAMの説明やリターンのために書かれたコメントで埋めなっていません。

答えて

1

これを解決するために、慣習に基づいてルーティングを行う代わりに、attribute routingを使用します。

まずルート

[HttpGet] 
[Route("api/mycontroller")] 
public HttpResponseMessage Get1(string p1, string p2= "blend", string p3 = "blend") 
//Call this api/mycontroller?p1=valueOne&p2=valueTwo&p3=valueThree 

[HttpGet] 
[Route("api/mycontroller/{p1}/p2/p3")] 
public HttpResponseMessage Get2(string p1,string p2= "blend", string p3 = "blend") 
//Call this api/mycontroller/valueOne/valueTwo/valueThree 
と制御方法をDECORE WebApiConfig.csに

config.MapHttpAttributeRoutes(); 

それを有効

関連する問題