我在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.
答案 0 :(得分:0)
通过检查applicationhost.config文件行
,确保在GoDaddy服务器上的IIS上启用update()
谓词
PUT
简单地在那里添加<add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
动词,因为它默认是禁用的。
答案 1 :(得分:0)
我用post方法解决了我的问题而不是put方法。 谢谢Ipsit Gaur