WebAPI帮助页面:禁用正式发布 [英] WebAPI Help Pages: disable for Production release

查看:356
本文介绍了WebAPI帮助页面:禁用正式发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在VS 2010中使用较旧的WCF框架开发了许多内部REST接口。对于DEV和QA平台,它能够生成帮助页面的功能非常方便,但是对于生产版本而言,很容易禁用 web.config 文件中的以下帮助页面:

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"/>

我现在正在继续使用WebAPI框架(当前是VS 2012的版本1),但是关闭此功能似乎并不简单(即,在web.config文件中找不到有关如何执行此操作的任何信息)。

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).

当然,我可以继续在代码本身中手动执行此操作,但是肯定有更简单的方法;类似于WCF如何执行上述操作。我想使用web.config文件方法,因为我已经将web.release.config转换文件放置在其他设置中。

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.

推荐答案

相对于基于web.config的启用,Web API没有现成的支持或禁用帮助页面。

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:


  • 由于HelpPage是作为MVC区域安装的,因此在部署到
    生产环境时,您可以仅排除此 HelpPage 文件夹。

创建一个操作筛选器,该筛选器将返回404,如此处建议的那样:有条件地禁用ASP.NET MVC控制器

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

注意:对于上述情况,如果使用的是默认Web API模板,那么是的,您需要显示/不显示的其他步骤导航栏中的帮助链接。

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.

这篇关于WebAPI帮助页面:禁用正式发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆