如何注册已在 AREA 中创建的控制器 [英] How do I register a controller that has been created in an AREA

查看:17
本文介绍了如何注册已在 AREA 中创建的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MVC4 的 WEB API 来公开控制器.

I am using MVC4's WEB API to expose a controller.

最初我创建了一个MVC4 WEBAPI项目,设置项目不打开任何网页,等待外部应用调用URL(WEB API).VS2010 中的项目设置为从 IIS7 Express 运行,而不是 VS2010 的 Dev Server.这工作正常,浏览器提示我下载文件.这对我来说没问题,因为浏览器不知道如何处理返回的数据(RAW TEXT).

Initially I created created a MVC4 WEBAPI project, set the project not to open any web page, wait for an external app to call the URL (WEB API). The project in VS2010 is set to run from IIS7 Express, not VS2010's Dev Server. This works OK, the browser prompts me to down load a file. Which is OK for me, as the browser does not know what to do with the returned data (RAW TEXT).

接下来,我在MVC4项目区创建了一个AREA,然后添加了一个控制器(WEB API类型).

Next, I created an AREA in the MVC4 project area, then added a controller (WEB API type).

然后我再次运行该项目并在浏览器中输入 URL (WEB API).它失败了.

Then I once again ran the project and in a browser entered the the URL (WEB API). And it fails.

编辑

推荐答案

默认情况下 DefaultHttpControllerFactory 不适用于区域.要获得此功能,您必须编写自定义 HttpControllerFactory.

The DefaultHttpControllerFactory doesn't work with Areas by default. To get this functionality you have to write your custom HttpControllerFactory.

您可以在 如何创建HttpControllerFactory来支持区域

这篇关于如何注册已在 AREA 中创建的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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