任何帮助将不胜感激。我已经研究这个问题几天了。这就是正在发生的事情。
我在 vs 2012 中使用 mvc4 下的模板创建了我的第一个 WebApi 服务。我保留了大部分默认设置。我确实更改了 WebApiConfig 中的路由器。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace GetBalanceSV
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "SubscriberActivity/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
我可以在我的机器上以 Debug模式正常运行。我通过 VS2012 在我的机器上发布,并使用 IIS 将其作为自主机运行,并且可以调用 get 方法并毫无问题地获得响应。使用
"http://localhost/SubscriberActivity/Values/Testingingmystring"
我还可以将其部署在带有 IIS 的 Web 开发服务器上,作为自托管中的新网站,这样就可以在服务器上正常运行。但是当我使用相同的应用程序池放置在现有网站下时,它会失败。 404 错误。
我通过 fiddler2 运行了这个,这就是我得到的响应。
*HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 Oct 2013 17:04:59 GMT
Content-Length: 1937
<!DOCTYPE html>
<html>
<head>
<title>The resource cannot be found.</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/SubscriberActivity' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
<br><br>
<b> Requested URL: </b>/SubscriberActivity/values/testeing<br><br>
</body>
</html>*
有人知道为什么会发生这种情况吗?
最佳答案
检查现有应用程序池是处于经典模式还是集成模式。如果是经典模式则更改为集成模式
关于asp.net-mvc-4 - 使用 IIS 7 在服务器上部署时,WebAPI 显示 404 错误,但作为 selfhost 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19231535/