任何帮助将不胜感激。我已经研究这个问题几天了。这就是正在发生的事情。
我在 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 }
);
}
}
}
我可以在我的机器上以调试模式运行它。我通过 VS2012 在我的机器上发布并使用 IIS 作为自主机运行它,并且可以调用 get 方法并毫无问题地得到响应。使用
"http://localhost/SubscriberActivity/Values/Testingingmystring"
我也可以将它部署在我们的 Web 开发服务器上,使用 IIS 作为自托管中的新网站,并且可以在服务器上正常运行。但是,当我使用相同的应用程序池放置在现有网站下时,它会失败。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>*
有谁知道为什么会发生这种情况?