我在 web-api 中使用了两种方法类型。它在 localhost 中是正确的。但是当我在 godaddy 服务器上使用它时它不正确并且我有错误 405。
[RoutePrefix("api/MyController")]
public class MyController : ApiController
{
[HttpPut]
[Route("Method1")]
public returnObject Method1([FromBody]object1 object)
{
return returnObject1
}
[HttpPut]
[Route("Method2")]
public returnObject2 Method2([FromBody]object2 object)
{
return returnObject2
}
}
但是我无法访问godaddy服务器中的applicationhost.config,但是我尝试在我的项目中使用此代码添加此部分。
using (ServerManager serverManager = new ServerManager())
{
Configuration configAdmin = serverManager.GetApplicationHostConfiguration();
var section = configAdmin.GetSection("system.webServer/modules", "");
var collection = section.GetCollection();
var element = collection.CreateElement();
element.Attributes["name"].Value = "ExtensionlessUrl-Integrated-4.0";
element.Attributes["path"].Value = "*.";
element.Attributes["verb"].Value = "GET,HEAD,POST,DEBUG";
element.Attributes["type"].Value = "System.Web.Handlers.TransferRequestHandler";
element.Attributes["preCondition"].Value = "integratedMode,runtimeVersionv4.0";
collection.Add(element);
serverManager.CommitChanges();
}
when i run project and run up to line element.Attributes["path"] this is null and i have error.