【问题标题】:Can i use multiple method type put on godaddy server?我可以在godaddy服务器上使用多种方法类型吗?
【发布时间】:2018-03-16 21:15:03
【问题描述】:

我在 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.

【问题讨论】:

    标签: asp.net-web-api asp.net-web-api2 asp.net-web-api-routing godaddy-api


    【解决方案1】:

    只需通过检查 applicationhost.config 文件的行来确保在 GoDaddy 服务器上的 IIS 上启用了 PUT 动词

    <add name="ExtensionlessUrl-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    

    只需在此处添加 PUT 动词,因为它默认是禁用的。

    【讨论】:

    • 但我无法访问 godaddy 服务器中的 applicationhost.config 但是我尝试在我的项目中添加此代码。
    【解决方案2】:

    我使用 post 方法而不是 put 方法解决了我的问题。 谢谢 Ipsit Gaur

    【讨论】:

      猜你喜欢
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      相关资源
      最近更新 更多