Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAPI Help Pages: disable for Production release

I have developed a number of internal REST interfaces using the older WCF framework in VS 2010. The ability for it to generate help pages was handy for DEV and QA platforms, but for a production release it was easy to disable the generation of these help pages in the web.config file:

<standardEndpoint name="" helpEnabled="false" automaticFormatSelectionEnabled="true"/>

I am now moving on to use the WebAPI framework instead (currently version 1 on VS 2012), but it doesn't appear to be as trivial to turn this feature off (i.e. I can't find any information on how to do this in a web.config file).

Certainly I can go ahead and do this by hand within the code itself, but surely there's an easier way; something akin to how WCF did it as described above. I'd like to use the web.config file approach since I already have the web.release.config transform files in place for other settings.

Any thoughts on best practices on this would be appreciated.

like image 576
GoodEnuf Avatar asked Jun 11 '14 16:06

GoodEnuf


People also ask

How do I disable Web API?

Simply go to the plugins page and search it by name. Once the plugin has been installed and activated, click on Settings > Disable REST API to head over to the main settings page for the plugin. You will see this located in the left side menu area of your admin dashboard.

Which one from the following will run on top of ASP Net Web API help pages?

NuGet packages (37) A simple Test Client built on top of ASP.NET Web API Help Page.


2 Answers

Open the Global.asax.cs,modify your code like the following snippet code:

#if DEBUG
   AreaRegistration.RegisterAllAreas();
#endif

Because the help page is in the Area named 'HelpPage',so we can ignore it by the above code in the release or production environment.

like image 86
Farb Avatar answered Sep 17 '22 03:09

Farb


Web API doesn't have an out of box support with respect to web.config based enabling or disabling of helppage.

Some options you can consider:

  • Since HelpPage is installed as an MVC area, when deploying to production you could just exclude this HelpPage folder.

  • Create an action filter which returns 404 as suggested here: Conditionally disable ASP.NET MVC Controller

NOTE: for the above cases, if you are using the default Web API template, then yeah you would need additional step of display/not display the Help link from the navigation bar.

like image 28
Kiran Avatar answered Sep 18 '22 03:09

Kiran