我有一个控制器,它在 localhost 上对所有使用的动词都可以正常工作,但是在 IIS 7 上 DELETE 失败,给出 404。网络服务器没有安装 webdav,绝望中我也关闭了 FTP :) 我只是不知道还有哪里可以看。
我的控制器:
[HttpDelete]
public HttpResponseMessage Delete()
{
oTrace T = new oTrace();
T.trace("deprovision request");
string headers = Request.Headers.Authorization.ToString().Split(' ')[1];
string userpwd = WebConfigurationManager.AppSettings["xxxxuserpwd"];
//try
//{
string basicData = System.Text.ASCIIEncoding.ASCII.GetString(System.Convert.FromBase64String(headers));
if (basicData != userpwd)
{
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
}
else
{
string[] paths = Request.RequestUri.ToString().Split('/');
Guid Unique = new Guid(paths[paths.Length - 1]);
//HttpContent requestContent = Request.Content;
//string jsonContent = requestContent.ReadAsStringAsync().Result;
//oProvision myProvision = JsonConvert.DeserializeObject<oProvision>(jsonContent);
//string JSONresponse = @"{""id"":""1"", ""config"": { ""xxON_UNIQUE"":""" + Convert.ToString(Unique) + @"""} }";
var response = this.Request.CreateResponse(HttpStatusCode.OK);
//response.Content = new StringContent(JSONresponse, Encoding.UTF8, "application/json");
////kick off GetAppInfoRequest
BackgroundWorker barInvoker = new BackgroundWorker();
barInvoker.DoWork += delegate
{
Thread.Sleep(TimeSpan.FromSeconds(10));
deProvisionAddon(Unique);
};
barInvoker.RunWorkerAsync();
return response;
}
}
我的 web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
我的 webapi.config
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "heroku/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DeleteApi",
routeTemplate: "heroku/{controller}/Delete/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.EnableSystemDiagnosticsTracing();
}
由于我已经为此奋斗了好几天,因此感激地获得了任何帮助。