ASP.NET MVC和IIS 5
时间:2020-03-05 18:51:51 来源:igfitidea点击:
什么是使ASP.NET MVC应用程序托管在IIS 5(6或者7)上的最佳方法是什么。当我尝试发布ASP.NET MVC应用程序时,似乎只有404错误。我做了一些谷歌搜索,找到了两个解决方案,但是似乎都不是很优雅,而且我担心一旦我开始为应用程序使用共享托管环境,它们是否将无法使用。
解决方案1
Right-click your application virtual directory on inetmgr.exe. Properties->Virtual Directory Tab-> Configuration. Add a new mapping extension. The extension should be .*, which will be mapped to the Executable C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll, or the appropriate location on your computer (you can simply copy this from the mapping for .aspx files). On the mapping uncheck "check that file exists". 3 X OK and you're good to go. If you want, you can apply this setting to all your web sites. In step1, click on the "Default Web Site" node instead of your own virtual directory, and in step 2 go to the "Home Directory" tab. The rest is the same.
通过ASP.NET路由所有内容似乎有点技巧。
解决方案2
编辑MVC路由以在URL中包含.mvc,然后根据此扩展名遵循解决方案1中的步骤。编辑:原始图像链接丢失了,但是这里来自Google的缓存:
解决方案
回答
我们是否尝试过将.aspx添加到控制器名称的末尾?
它适用于Stack Overflow问题,在哪里可以得到ASP.NET MVC托管?
回答
答案在这里
If *.mvc extension is not registered to the hosting , it will give 404 exception. The working way of hosting MVC apps in that case is to modify global.asax routing caluse in the following way. routes.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary (new{ controller = "YourController"} ) }); In this way all your controller request will end up in *.mvc.aspx, which is recognized by your hosting. And as the MVC dlls are copied into your local bin , no special setttings need to be done for it.
回答
我认为无论哪种方式,我们都必须执行解决方案1.
考虑HTTP请求管道。
- 一个请求进入IIS。
- IIS检查端口/主机头,以查看它是否设置了一个网站来捕获对该主机头/端口的请求。
- IIS研究请求的文件扩展名(.php,.asp,.aspx),并将其交给可处理该类型请求的ISAPI。
仅在这一点上,ASP.NET(或者PHP运行时)才会启动。如果IIS没有该映射,则它将永远不会将请求传递给ASP.NET运行时,并且该请求将永远不会到达代码。这就是为什么我们需要将该glob(*)映射到ASP.NET ISAPI的原因。
ASP.NET MVC框架的URL通常以根本没有文件扩展名结尾。如果希望这些请求由ASP.NET(或者某些其他运行时)处理,则必须映射所有请求,而不管该ISAPI(即aspnet_isapi.dll)的文件扩展名如何。
对于需要提供媒体服务(例如.jpg,.gif)的HttpHandler,通常也可以这样做。为了使处理程序起作用,即使.jpg不是"常规" ASP.NET文件扩展名,也需要将其映射到代码。
HTH,
泰勒
回答
仅供参考:在服务器2003(正在开发必须连接到RPS的应用程序)上,它不允许我添加扩展名*,我使用了替代解决方案来修改route子句,并且
工作了。