任何帮助将不胜感激。我已经研究这个问题几天了。 这是正在发生的事情。
我在 vs 2012 中使用 mvc4 下的 templete 创建了我的第一个 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"
我还可以将 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>*
有谁知道为什么会发生这种情况?
检查现有应用程序池是处于经典模式还是集成模式。如果是经典模式,则将其更改为集成模式
我不确定"但是当我使用相同的应用程序池放在现有网站下时,它失败了"是什么意思。但无论如何,我相信你的问题出在:
-
也许 IIS 需要更新以支持无扩展名 URL(除非它已经托管在同一个 IIS 上工作正常,这意味着它已经支持它)。 检查这个
-
确保 http 处理程序正确(查看 Visual Studio 中 web.config 中的部分,并确保部署的版本具有相同的 http 处理程序)。恐怕您部署的方式错误。
您也可以查看此链接