ASP.NET MVC 和 IIS 5 [英] ASP.NET MVC and IIS 5

查看:31
本文介绍了ASP.NET MVC 和 IIS 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让 ASP.NET MVC 应用程序在 IIS 5(6 或 7)上运行的最佳方式是什么?当我尝试发布我的 ASP.NET MVC 应用程序时,我似乎得到的只是 404 错误.我已经做了一些谷歌搜索,并找到了几个解决方案,但似乎都不是超级优雅,我担心一旦我开始为应用程序使用共享托管环境,它们是否会无法使用.

<块引用>

如果 *.mvc 扩展名未注册到托管,它会给 404例外.托管的工作方式MVC 应用程序在这种情况下是修改global.asax 中的路由调用以下方式.

routes.Add(new路由({控制器}.mvc.aspx/{动作}",新 MvcRouteHandler()) {默认值 = 新 RouteValueDictionary(新{控制器= "YourController"} ) });

这样你所有的控制器请求将在 *.mvc.aspx 中结束,这是您的主机认可的.随着 MVC dll 被复制到您的本地垃圾箱,没有特殊设置需要为它做.

What is the best way to get hosting of an ASP.NET MVC application to work on IIS 5 (6 or 7). When I tried to publish my ASP.NET MVC application, all I seemed to get is 404 errors. I've done a bit of googleing and have found a couple of solutions, but neither seem super elegant, and I worry if they will be unusable once I come to use a shared hosting environment for the application.

Solution 1

  1. Right-click your application virtual directory on inetmgr.exe.
  2. Properties->Virtual Directory Tab-> Configuration.
  3. Add a new mapping extension. The extension should be .*, which will be mapped to the Executable C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_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".
  4. 3 X OK and you're good to go.
  5. 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.

It seems a tad hacky to route everything through ASP.NET.

Solutions 2

Edit the MVC routing to contain .mvc in the URL and then follow the steps in solution 1 based around this extension. Edit: The original image link was lost, but here it is from Google's Cache:

解决方案

Answer is here

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.

这篇关于ASP.NET MVC 和 IIS 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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