asp.net-mvc ASP.NET MVC 和 IIS 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/57712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 22:44:55  来源:igfitidea点击:

ASP.NET MVC and IIS 5

asp.net-mvciisshared-hosting

提问by Dan

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.

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

Solution 1

解决方案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:\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".
  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.
  1. 右键单击 inetmgr.exe 上的应用程序虚拟目录。
  2. 属性->虚拟目录选项卡->配置。
  3. 添加新的映射扩展。扩展名应该是 .*,它将映射到可执行文件 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,或您计算机上的适当位置(您可以简单地从映射中复制它.aspx 文件)。在映射上取消选中“检查该文件是否存在”。
  4. 3 X OK,你可以开始了。
  5. 如果需要,您可以将此设置应用到您的所有网站。在步骤 1 中,单击“默认网站”节点而不是您自己的虚拟目录,然后在步骤 2 中转到“主目录”选项卡。其余的都是一样的。

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

通过 ASP.NET 路由所有内容似乎有点麻烦。

Solutions 2

解决方案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:

编辑 MVC 路由以在 URL 中包含 .mvc,然后按照基于此扩展的解决方案 1 中的步骤进行操作。编辑:原始图像链接丢失了,但它来自谷歌的缓存:

alt text

替代文字

采纳答案by Dan

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.

如果 *.mvc 扩展名未注册到托管,则会出现 404 异常。在这种情况下,托管 MVC 应用程序的工作方式是按以下方式修改 global.asax 路由调用。

route.Add(new Route("{controller}.mvc.aspx/{action}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary (new{ controller = "YourController"} ) });

通过这种方式,您的所有控制器请求都将在 *.mvc.aspx 中结束,您的主机可以识别它。并且由于 MVC dll 被复制到您的本地 bin 中,因此不需要对其进行特殊设置。

回答by Tyler

I think either way you'll have to do Solution 1.

我认为无论哪种方式,您都必须执行 Solution 1

Consider the HTTP Request pipeline.

考虑 HTTP 请求管道。

  1. A request comes into IIS.
  2. IIS checks port/host header to see if it has a web site set up to capture requests for that host header/port.
  3. IIS investigates the file extension of the request (.php, .asp, .aspx) and hands it off to an ISAPI that can handle that type of request.
  1. 一个请求进入 IIS。
  2. IIS 检查端口/主机头以查看它是否设置了一个网站来捕获对该主机头/端口的请求。
  3. IIS 调查请求的文件扩展名(.php、.asp、.aspx)并将其交给可以处理该类型请求的 ISAPI。

Only at this point does ASP.NET (or a PHP runtime) kick in.If IIS does't have that mapping then it'll never hand off the request to the ASP.NET runtime and the request will never reach your code. That's why you need that glob (*) mapping to the ASP.NET ISAPI.

只有此时 ASP.NET(或 PHP 运行时)才会启动。如果 IIS 没有该映射,那么它永远不会将请求移交给 ASP.NET 运行时,并且该请求将永远不会到达您的代码。这就是为什么需要将 glob (*) 映射到 ASP.NET ISAPI 的原因。

ASP.NET MVC framework urls often end with no file extension at all. If you want these requests to get handled by ASP.NET (or some other runtime) you have to map all requests regardless of the file extension to that ISAPI (ie. aspnet_isapi.dll).

ASP.NET MVC 框架 url 通常以根本没有文件扩展名结尾。如果您希望这些请求由 ASP.NET(或其他一些运行时)处理,您必须将所有请求映射到该 ISAPI(即 aspnet_isapi.dll),而不管文件扩展名如何。

This is often also done for HttpHandlers that need to serve off media like .jpg, .gif. For the handler to be hit it needs to get mapped to your code even though .jpg isn't a "normal" ASP.NET file extension.

这通常也适用于需要提供 .jpg、.gif 等媒体的 HttpHandler。对于要命中的处理程序,它需要映射到您的代码,即使 .jpg 不是“正常”的 ASP.NET 文件扩展名。

HTH,
Tyler

HTH,
泰勒

回答by ranni rabadi

Run: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll -i

运行:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll -i

This will reset IIS registry settings for aspnet user.

这将重置 aspnet 用户的 IIS 注册表设置。

Create the virtual directory: 1. Right click on the directory you want to convert

创建虚拟目录: 1. 右键单击​​要转换的目录

  • select Properties
    1. under Directory, select Create.
    2. under Configuration, select Add.
    3. for Executable insert:
  • 选择属性
    1. 在目录下,选择创建。
    2. 在配置下,选择添加。
    3. 对于可执行插入:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

for Extension insert: .*

对于扩展插入:.*

  • uncheck “Check that file exists”

  • under Documents add entry point file, ie: Default.htm, index.htm, Global.asax

  • under Directory Settings

    1. select Edit...
    2. select Anonymous access
    3. uncheck Allow IIS to control password
    4. uncheck Basic authentication
    5. uncheck Integrated Windows authentication
    6. under ASP.NET, make sure version = v4.0.30319
  • 取消选中“检查文件是否存在”

  • 在 Documents 下添加入口点文件,即:Default.htm、index.htm、Global.asax

  • 在目录设置下

    1. 选择编辑...
    2. 选择匿名访问
    3. 取消选中允许 IIS 控制密码
    4. 取消选中基本身份验证
    5. 取消选中集成 Windows 身份验证
    6. 在 ASP.NET 下,确保 version = v4.0.30319

TAKE NOTE of User Name ie: IUSR_AVSJ82S

记下用户名,即:IUSR_AVSJ82S

Set sharing permission of physical directory:

设置物理目录共享权限:

  • In windows explorer, go to the physical directory that was converted to a virtual directory. Right click the directory name
  • select properties
  • under security tab, select Add
  • enter the IIS User name ie: IUSR_AVSJ82S click check name.
  • click OK
  • set permissions to Read and Write.
  • 在 Windows 资源管理器中,转到已转换为虚拟目录的物理目录。右键单击目录名称
  • 选择属性
  • 在安全选项卡下,选择添加
  • 输入 IIS 用户名即:IUSR_AVSJ82S 点击检查名称。
  • 单击确定
  • 设置读写权限。

回答by Eric Brown - Cal

FYI:On server 2003 (developing an app that had to connect to the RPS), it didnt' allow me to add the extension .*, I used the alternate solution modifying the route clause, and that worked.

仅供参考:在服务器 2003(开发必须连接到 RPS 的应用程序)上,它不允许我添加扩展名 .*,我使用了修改路由子句的替代解决方案,并且有效。

回答by Iain Holder

Have you tried adding .aspx to the end of the controller name?

您是否尝试将 .aspx 添加到控制器名称的末尾?

It worked for Stack Overflow question Where can I get ASP.NET MVC hosting?.

它适用于堆栈溢出问题我在哪里可以获得 ASP.NET MVC 托管?.