【发布时间】:2011-12-12 12:49:05
【问题描述】:
当我的干净、刚刚创建的新应用程序(.net 4.0 集成)在 Visual Studio Web 服务器上时,一切正常。像下面这样的链接工作正常,控制器返回图像。
http://localhost:12345/image/a.jpg
但是当我在 IIS 7.5 上运行这个应用程序时,iis 会控制并报告 404。
http://localhost/testmvc3/image/a.jpg
控制器:
public class ImageController : Controller
{
public ActionResult Index(string name)
{
var dir = Server.MapPath("~/content/" + name);
return File(dir, "image/jpg");
}
}
路线:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Image", // Route name
"image/{*name}", // URL with parameters
new { controller = "Image", action = "Index", name = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
我应该改变什么才能正常运行这个应用程序?
编辑1:
问题在于扩展。当我删除扩展时,请求指向图像控制器。使用扩展名 (jpg) iis 首先接受请求(为什么!?)并返回 404(不涉及图像控制器操作)。
EDIT2:
- Windows 7 64 位上的 IIS 7.5
- Framework 4.0 集成管道上的应用
我的更改之前的 web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
【问题讨论】:
标签: asp.net-mvc-3 .net-4.0 routing iis-7.5