将 MVC2 应用程序部署到 IIS7.5 - Ninject 要求提供内容文件的控制器

发布于 2024-08-31 09:08:12 字数 1164 浏览 5 评论 0原文

我有一个应用程序,它最初是 Visual Studio 2008 Sp1 中的 MVC (1.0) 应用程序,其中有一堆 Silverlight 3 项目作为网站的一部分。一点也不花哨。使用 Ninject 进行依赖注入(第一个版本 2 beta,现在发布带有 MVC 扩展的版本 2)。

随着.Net 4.0、VS2010、MVC2等的发布,我们决定将应用程序迁移到最新的平台。 VS2010 中的转换向导显然处理了所有事情,但有一个例外 - 它没有将对 mvc1 的引用更改为现在指向 mvc2,因此我必须手动执行此操作。当然,这让我想到我的应用程序中可能缺少的其他 MVC2 东西,如果我执行 File -> ,这些东西就会存在。新项目...但这不是这个问题的重点。

当我将此应用程序部署到 IIS 7.5 服务器(在 Win2008 R2 x64 上运行)时,该应用程序本身就可以工作。然而,图像、脚本和其他静态内容似乎并不存在。当然,它们位于服务器的磁盘上,但不会显示在客户端 Web 浏览器中。

我对 IIS 相当陌生,所以我知道的唯一技巧就是尝试在服务器上的浏览器中打开网页,因为这可以给我更多信息。在这里,我们终于遇到了我们的敌人。如果我尝试直接转到其中一张图像的 URL (http://server/Content/someimage.jpg 例如),我在浏览器中收到以下错误:

IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' 没有返回名为 'Content' 的控制器的控制器。

啊哈。 Web 服务器尝试将此请求提供给 MVC,MVC 的默认路由设置假定内容是控制器,但失败了。

如何让它将 Content/ 和 Scripts/ (以及其他)视为非控制器并仅传递静态内容?这当然可以在我的开发机器上使用 Cassini,但是一旦我部署,这个问题就出现了。

我正在使用 Ninject MVC 2 的最新版本,其中 IoC 工具应该将丢失的控制器传递给基本控制器工厂,但这显然没有帮助。我还尝试为内容等添加忽略路由,但这显然也没有效果。我什至不确定我是否在正确的层面上解决问题。

有谁知道在哪里可以找到这个应用程序?我可以完全控制网络服务器,因此只要它开始工作,我就可以或多或少地做任何我想做的事情。

谢谢!

I have an application that started life as an MVC (1.0) app in Visual Studio 2008 Sp1 with a bunch of Silverlight 3 projects as part of the site. Nothing fancy at all. Using Ninject for dependency injection (first version 2 beta, now the released version 2 with the MVC extensions).

With the release of .Net 4.0, VS2010, MVC2 etc., we decided to move the application to the newest platform. The conversion wizard in VS2010 apparently took care of everything, with one exception - it didn't change references to mvc1 to now point to mvc2, so I had to do that manually. Of course, this makes me think about other MVC2 things that could be missing from my app, that would be there if I did File -> New Project... But that is not the focus of this question.

When I deploy this application to the IIS 7.5 server (running on Win2008 R2 x64), the application as such works. However, images, scripts and other static content doesn't seem to exist. Of course they are there on disk on the server, but they don't show up in the client web browser.

I am fairly new to IIS, so the only trick I knew is to try to open the web page in a browser on the server, as that could give me more information. And here, finally, we meet our enemy. If I try to go directly to the URL of one of the images (http://server/Content/someimage.jpg for instance), I get the following error in the browser:

The IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for a controller named 'Content'.

Aha. The web server tries to feed this request to MVC, who with its' default routing setup assumes Content to be a controller, and fails.

How can I get it to treat Content/ and Scripts/ (among others) as non-controllers and just pass through the static content? This of course works with Cassini on my developer machine, but as soon as I deploy, this problem hits.

I am using the last version of Ninject MVC 2 where the IoC tool should pass missing controllers to the base controller factory, but this has apparently not helped. I have also tried to add ignore routes for Content etc., but this apparently has no effect either. I am not even sure I am addressing the problem on the right level.

Does anyone know where to look to get this app going? I have full control of the web server so I can more or less do whatever I want to it, as long as it starts working.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抠脚大汉 2024-09-07 09:08:12

我对 StructureMap 和 favorite.ico 也有类似的问题,我最终做的是添加一条路线来忽略该路径。

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

请记住,我完全不知道,但另一件事发生了变化,那就是需要 Default.aspx,而且如果您有任何需要映射的自定义页面。这是我在路由方面遇到的唯一两个问题。

        routes.RouteExistingFiles = false;

编辑:我的意思是 RouteExistingFiles 应该为 false,否则我会在 MVC2 中遇到该异常:)

I had a similar problem with StructureMap and favorite.ico what I ended up doing was to add a route to ignore that path.

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("favicon.ico");

Keep in mind that I have absolutely no idea really but another thing that changed is the need for Default.aspx, also if you have any custom pages those would need to mapped. That's the only two problems I had with routing.

        routes.RouteExistingFiles = false;

EDIT: I meant that the RouteExistingFiles should be false otherwise I get that exception in MVC2 :)

美人迟暮 2024-09-07 09:08:12

事实证明,这是由某些帐户设置引起的 - 我不知道 Win2008 R2 服务器中的 IIS 自动创建了 IIS AppPool\sitename 帐户。在尝试了“一切”之后,我发现了这些信息,给予了适当的权限,然后事情就神奇地开始工作了。

调试起来相当困难,特别是对于 IIS 经验非常有限的人(我)来说。

Turns out this was caused by some account settings - I was unaware of the IIS AppPool\sitename account automatically being created by IIS in Win2008 R2 server. After trying "everything", I came across this information, gave the proper rights, and stuff magically started working.

Pretty hard thing to debug, especially for someone (me) with very limited IIS experience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文