webapi.helppage package added but apiexplorer is n

2019-08-14 15:38发布

I have a .NET 4.5 MVC 4 project which I have added the webapi.helppage package to it via NuGet.

Then added an ApiController to my project of the below:

public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/values/5
    public void Delete(int id)
    {
    }
}

to see if the help page is working, but it returns an empty apidescription collection for the below GetApiExplorer() call:

    public ActionResult Index()
    {
        return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
    }

I can however use the example api controller by navigating to /api/values for example.

Anyone know why the apidescription wouldn't be found?

1条回答
你好瞎i
2楼-- · 2019-08-14 16:06

I made a new web api project and started adding in my installed NuGet packages one by one and it turns out Glimpse is what is causing these not to display.

I found more information here: ASP.Net Web API Help Page returning empty output

and the most appropriate work around so far is to add the below to the web.config glimpse section:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<inspectors>
      <ignoredTypes>
        <add type="Glimpse.AspNet.Inspector.RoutesInspector, Glimpse.AspNet"/>
      </ignoredTypes>
    </inspectors>
</glimpse>
查看更多
登录 后发表回答