角$资源POST / PUT到的WebAPI 405不允许的方法 [英] Angular $resource POST/PUT to WebAPI 405 Method Not Allowed

查看:2336
本文介绍了角$资源POST / PUT到的WebAPI 405不允许的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到有益的回答以下问题。结果,
角$资源POST / PUT(两者)产生405.0 - 一个简单的WebAPI调用不允许的方法错误。找工作就好了。应用与的WebAPI一个MVC在IIS 7.5上运行。当我尝试在本地运行一个示例 - 工作正常。这不是一个CORS问题,验证被剥离出来。

http://portal.local.com/api/products/5 405(不允许的方法)

\r
\r

<!DOCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0 Strict标准// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>\r
\r
< HEAD>\r
  <标题> IIS 7.5的详细错误 - 405.0 - 不允许的方法< /标题>\r
  <风格类型=文/ CSS>\r
    <! - 身体{\r
      保证金:0;\r
      字体大小:.7em;\r
      FONT-FAMILY:宋体,宋体,黑体,无衬线;\r
      背景:#CBE1EF;\r
    }\r
    code {\r
      保证金:0;\r
      颜色:#006600;\r
      字体大小:1.1em;\r
      字体重量:大胆的;\r
    }\r
    .config_source code {\r
      字体大小:.8em;\r
      颜色:#000000;\r
    }\r
    pre {\r
      保证金:0;\r
      字体大小:1.4em;\r
      自动换行:打破字;\r
    }\r
    UL,\r
    OL {\r
      保证金:10px的0 10px的40像素;\r
    }\r
    ul.first,\r
    ol.first {\r
      的margin-top:5像素;\r
    }\r
    字段集{\r
      填充:0 15px的10px的15px的;\r
    }\r
    。总结容器字段集{\r
      填充底:5像素;\r
      的margin-top:4PX;\r
    }\r
    legend.no展开,所有{\r
      填充:2px的均为15px 10px的4PX;\r
      保证金:0 0 0 -12px;\r
    }\r
    传说{\r
      颜色:#333333;\r
      填充:4PX均为15px 10px的4PX;\r
      保证金:4PX 0 8像素-12px;\r
      _margin顶:0像素;\r
      边境顶:1px的固体#EDEDED;\r
      左边框:1px的固体#EDEDED;\r
      右边框:1px的固体#969696;\r
      下边框:1px的固体#969696;\r
      背景:#E7ECF0;\r
      字体重量:大胆的;\r
      字体大小:1EM;\r
    }\r
    一条链接,\r
    答:访问{\r
      颜色:#007EFF;\r
      字体重量:大胆的;\r
    }\r
    答:悬停{\r
      文字修饰:无;\r
    }\r
    H1 {\r
      字体大小:2.4em;\r
      保证金:0;\r
      颜色:#FFF;\r
    }\r
    H2 {\r
      字体大小:1.7em;\r
      保证金:0;\r
      颜色:#CC0000;\r
    }\r
    H3 {\r
      字体大小:1.4em;\r
      保证金:10px的0 0 0;\r
      颜色:#CC0000;\r
    }\r
    H4 {\r
      字体大小:1.2em;\r
      保证金:10px的0为5px 0;\r
    }\r
    {的#header\r
      宽度:96%;\r
      保证金:0 0 0 0;\r
      填充:6像素2%6像素2%;\r
      FONT-FAMILY:投石机MS,宋体,无衬线;\r
      颜色:#FFF;\r
      背景颜色:#5C87B2;\r
    }\r
    #内容{\r
      保证金:0 0 0 2%;\r
      位置:相对;\r
    }\r
    。总结容器,\r
    .content容器{\r
      背景:#FFF;\r
      宽度:96%;\r
      的margin-top:8像素;\r
      填充:10px的;\r
      位置:相对;\r
    }\r
    .config_source {\r
      背景:#fff5c4;\r
    }\r
    .content容器p {\r
      保证金:0 0 10px的0;\r
    }\r
    #细节左{\r
      宽度:35%;\r
      浮动:左;\r
      保证金右:2%;\r
    }\r
    #细节右{\r
      宽度:63%;\r
      浮动:左;\r
      溢出:隐藏;\r
    }\r
    #server_version {\r
      宽度:96%;\r
      _height:1px的;\r
      最小高度:1px的;\r
      保证金:0 0 0为5px;\r
      填充:11像素的2%加上了8px 2%;\r
      颜色:#FFFFFF;\r
      背景颜色:#5A7FA5;\r
      下边框:1px的固体#C1CFDD;\r
      边境顶:1px的固体#4A6C8E;\r
      字体重量:正常;\r
      字体大小:1EM;\r
      颜色:#FFF;\r
      文本对齐:权利;\r
    }\r
    #server_version p ​​{\r
      保证金:为5px 0;\r
    }\r
    表{\r
      保证金:4PX 0 4PX 0;\r
      宽度:100%;\r
      边界:无;\r
    }\r
    TD,\r
    日{\r
      垂直对齐:首位;\r
      填充:0的3px;\r
      文本对齐:左;\r
      字体重量:大胆的;\r
      边界:无;\r
    }\r
    日{\r
      宽度:30%;\r
      文本对齐:权利;\r
      填充右:2%;\r
      字体重量:正常;\r
    }\r
    THEAD日{\r
      背景色:#ebebeb;\r
      宽度:25%;\r
    }\r
    #细节右次{\r
      宽度:20%;\r
    }\r
    表tr.alt TD,\r
    表tr.alt日{\r
      背景色:#ebebeb;\r
    }\r
    .highlight- code {\r
      颜色:#CC0000;\r
      字体重量:大胆的;\r
      字体样式:斜体;\r
    }\r
    .clear {\r
      明确:两者;\r
    }\r
    。$ P $ {pferred\r
      填充:0 2px的为5px为5px;\r
      字体重量:正常;\r
      背景:#006633;\r
      颜色:#FFF;\r
      字体大小:.8em;\r
    }\r
     - >\r
  < /风格>\r
\r
< /头>\r
\r
<身体GT;\r
  < D​​IV ID =头>\r
    < H1>在应用程序LITE_PORTAL&LT服务器错误; / H1>\r
  < / DIV>\r
  < D​​IV ID =SERVER_VERSION>\r
    < P> Internet信息服务7.5 LT; / P>\r
  < / DIV>\r
  < D​​IV ID =内容>\r
    < D​​IV CLASS =内容的容器>\r
      <&字段集GT;\r
        <传奇>错误总结< /传说>\r
        < H2> HTTP错误405.0 - 不允许的方法< / H>\r
        < H3>您正在寻找的,因为正在使用无效的方法(HTTP动词)是无法显示该页面< / H3 GT&;\r
      < /字段集>\r
    < / DIV>\r
    < D​​IV CLASS =内容的容器>\r
      <&字段集GT;\r
        <传奇>详细的错误信息与LT; /传说>\r
        < D​​IV ID =细节左>\r
          <表格边框=0的cellpadding =0CELLSPACING =0>\r
            < TR类=ALT>\r
              <第i个模块< /第i\r
              < TD> WebDAVModule< / TD>\r
            < / TR>\r
            &所述; TR>\r
              <第i通知和LT; /第i\r
              < TD>麻prequestHandler< / TD>\r
            < / TR>\r
            < TR类=ALT>\r
              <第i处理器< /第i\r
              < TD>的WebDAV< / TD>\r
            < / TR>\r
            &所述; TR>\r
              <第i个错误code< /第i\r
              < TD> 00000000< / TD>\r
            < / TR>\r
\r
          < /表>\r
        < / DIV>\r
        < D​​IV ID =细节 - 右>\r
          <表格边框=0的cellpadding =0CELLSPACING =0>\r
            < TR类=ALT>\r
              <第i个请求的URL< /第i\r
              < TD> HTTP://portal.local.com:80 / API /产品/ 5℃; / TD>\r
            < / TR>\r
            &所述; TR>\r
              <第i个物理路径< /第i\r
              < TD> C:\\ _开发\\应用程序\\ liteangular_portal \\ LiteAngular \\ API \\产品\\ 5℃; / TD>\r
            < / TR>\r
            < TR类=ALT>\r
              <第i个登录方法< /第i\r
              < TD>&匿名LT; / TD>\r
            < / TR>\r
            &所述; TR>\r
              <第i登录用户< /第i\r
              < TD>&匿名LT; / TD>\r
            < / TR>\r
\r
          < /表>\r
          < D​​IV CLASS =清除>< / DIV>\r
        < / DIV>\r
      < /字段集>\r
    < / DIV>\r
    < D​​IV CLASS =内容的容器>\r
      <&字段集GT;\r
        <传奇>最可能的原因:其中; /传说>\r
        < UL>\r
          <李方式>发送到使用LT不是由配置来处理请求的模块允许的HTTP动词Web服务器的请求; /李>\r
          <李方式>的请求被发送到包含无效的HTTP动词的服务器16; /李>\r
          <李>该请求的是静态内容,并含有比GET或HEAD&LT以外的HTTP动词; /李>\r
          <李>将请求发送到使用HTTP动词POST和默认文档的虚拟目录是一个静态文件不支持超过GET或HEAD&LT其他HTTP动词; /李>\r
        < / UL>\r
      < /字段集>\r
    < / DIV>\r
    < D​​IV CLASS =内容的容器>\r
      <&字段集GT;\r
        <传奇>可尝试:< /传说>\r
        < UL>\r
          <李方式>验证模块处理这个请求被送到启用动词列表中,并确保这个动词应该被允许的Web站点和LT; /李>\r
          <李方式>检查IIS日志文件,看看哪些动词是不允许的请求< /李>\r
          <立GT;创建跟踪规则以跟踪此HTTP状态code失败的请求。有关为失败的请求创建跟踪规则的详细信息,单击< A HREF =htt​​p://go.microsoft.com/fwlink/?LinkID=66439>此处< / A>< /李>\r
        < / UL>\r
      < /字段集>\r
    < / DIV>\r
\r
\r
    < D​​IV CLASS =内容的容器>\r
      <&字段集GT;\r
        <传奇>链接和更多信息< /传说>\r
        此错误表示发送到Web服务器的请求中包含的不被请求的配置模块允许处理一个HTTP动词。\r
        < P>< A HREF =htt​​p://go.microsoft.com/fwlink/?LinkID=62293&IIS70Error=405,0,0x00000000,7601>查看更多的信息和放大器; RAQUO;< / A>\r
        &所述; / P>\r
\r
      < /字段集>\r
    < / DIV>\r
  < / DIV>\r
< /身体GT;\r
\r
< / HTML>

\r

\r
\r

我可以为这一API的方法Ajax调用,所以他们应该罚款。我试着添加/删除的Http responseTyp的属性,他们都没有运气。一些web /角度大师可以提供一些线索对这个问题呢?有什么事情在IIS中?我发现这个: https://support.microsoft.com/en-us/kb/942051 这的http://www.c-sharpcorner.com/Blogs/47627/wepapi-http-error-405-0-method-not-allowed.aspx
但与IIS配置APPHOST搞乱似乎的hackish。而且我没有足够的熟悉它做出明智的决定。
编辑:我的配置:

\r
\r

< customHeaders>\r
  <添加名称=访问控制允许来源VALUE =*/>\r
  <添加名称=访问控制 - 允许 - 头VALUE =Content-Type的,接受授权/>\r
  <添加名称=访问控制允许的凭据VALUE =真/>\r
  <添加名称=访问控制允许的方法VALUE =POST,GET,PUT,DELETE,OPTIONS/>\r
  <添加名称=访问控制-max-age的值=1728000/>\r
< / customHeaders>

\r

\r
\r


        
        
        
        
                
      

在此先感谢!

P.S。它看起来像问题与WebDAVModule做:
通知马prequestHandler
处理器的WebDAV
错误code 0x0000000

任何人都知道它可能是有关系吗?有人吗?...


解决方案

原来删除WebDAV处理程序,并WebDAVModule照顾的问题:

 <&处理GT;
  <清除NAME =WebDAV的/>
< /处理器>
<模块runAllManagedModulesForAllRequests =真正的>
  <清除NAME =WebDAVModule/>
< /模块>

I wasn't able to find helpfull answer to the following problem.
Angular $resource POST/PUT (both) generate 405.0 - Method Not Allowed error on a simple WebAPI calls. Get works just fine. App is an MVC with WebAPI running in IIS 7.5. When I try to run a sample locally - works fine. It's not a CORS issue and Auth was stripped out.

PUT http://portal.local.com/api/products/5 405 (Method Not Allowed)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>IIS 7.5 Detailed Error - 405.0 - Method Not Allowed</title>
  <style type="text/css">
    <!-- body {
      margin: 0;
      font-size: .7em;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      background: #CBE1EF;
    }
    code {
      margin: 0;
      color: #006600;
      font-size: 1.1em;
      font-weight: bold;
    }
    .config_source code {
      font-size: .8em;
      color: #000000;
    }
    pre {
      margin: 0;
      font-size: 1.4em;
      word-wrap: break-word;
    }
    ul,
    ol {
      margin: 10px 0 10px 40px;
    }
    ul.first,
    ol.first {
      margin-top: 5px;
    }
    fieldset {
      padding: 0 15px 10px 15px;
    }
    .summary-container fieldset {
      padding-bottom: 5px;
      margin-top: 4px;
    }
    legend.no-expand-all {
      padding: 2px 15px 4px 10px;
      margin: 0 0 0 -12px;
    }
    legend {
      color: #333333;
      padding: 4px 15px 4px 10px;
      margin: 4px 0 8px -12px;
      _margin-top: 0px;
      border-top: 1px solid #EDEDED;
      border-left: 1px solid #EDEDED;
      border-right: 1px solid #969696;
      border-bottom: 1px solid #969696;
      background: #E7ECF0;
      font-weight: bold;
      font-size: 1em;
    }
    a:link,
    a:visited {
      color: #007EFF;
      font-weight: bold;
    }
    a:hover {
      text-decoration: none;
    }
    h1 {
      font-size: 2.4em;
      margin: 0;
      color: #FFF;
    }
    h2 {
      font-size: 1.7em;
      margin: 0;
      color: #CC0000;
    }
    h3 {
      font-size: 1.4em;
      margin: 10px 0 0 0;
      color: #CC0000;
    }
    h4 {
      font-size: 1.2em;
      margin: 10px 0 5px 0;
    }
    #header {
      width: 96%;
      margin: 0 0 0 0;
      padding: 6px 2% 6px 2%;
      font-family: "trebuchet MS", Verdana, sans-serif;
      color: #FFF;
      background-color: #5C87B2;
    }
    #content {
      margin: 0 0 0 2%;
      position: relative;
    }
    .summary-container,
    .content-container {
      background: #FFF;
      width: 96%;
      margin-top: 8px;
      padding: 10px;
      position: relative;
    }
    .config_source {
      background: #fff5c4;
    }
    .content-container p {
      margin: 0 0 10px 0;
    }
    #details-left {
      width: 35%;
      float: left;
      margin-right: 2%;
    }
    #details-right {
      width: 63%;
      float: left;
      overflow: hidden;
    }
    #server_version {
      width: 96%;
      _height: 1px;
      min-height: 1px;
      margin: 0 0 5px 0;
      padding: 11px 2% 8px 2%;
      color: #FFFFFF;
      background-color: #5A7FA5;
      border-bottom: 1px solid #C1CFDD;
      border-top: 1px solid #4A6C8E;
      font-weight: normal;
      font-size: 1em;
      color: #FFF;
      text-align: right;
    }
    #server_version p {
      margin: 5px 0;
    }
    table {
      margin: 4px 0 4px 0;
      width: 100%;
      border: none;
    }
    td,
    th {
      vertical-align: top;
      padding: 3px 0;
      text-align: left;
      font-weight: bold;
      border: none;
    }
    th {
      width: 30%;
      text-align: right;
      padding-right: 2%;
      font-weight: normal;
    }
    thead th {
      background-color: #ebebeb;
      width: 25%;
    }
    #details-right th {
      width: 20%;
    }
    table tr.alt td,
    table tr.alt th {
      background-color: #ebebeb;
    }
    .highlight-code {
      color: #CC0000;
      font-weight: bold;
      font-style: italic;
    }
    .clear {
      clear: both;
    }
    .preferred {
      padding: 0 5px 2px 5px;
      font-weight: normal;
      background: #006633;
      color: #FFF;
      font-size: .8em;
    }
    -->
  </style>

</head>

<body>
  <div id="header">
    <h1>Server Error in Application "LITE_PORTAL"</h1>
  </div>
  <div id="server_version">
    <p>Internet Information Services 7.5</p>
  </div>
  <div id="content">
    <div class="content-container">
      <fieldset>
        <legend>Error Summary</legend>
        <h2>HTTP Error 405.0 - Method Not Allowed</h2> 
        <h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.</h3> 
      </fieldset>
    </div>
    <div class="content-container">
      <fieldset>
        <legend>Detailed Error Information</legend>
        <div id="details-left">
          <table border="0" cellpadding="0" cellspacing="0">
            <tr class="alt">
              <th>Module</th>
              <td>WebDAVModule</td>
            </tr>
            <tr>
              <th>Notification</th>
              <td>MapRequestHandler</td>
            </tr>
            <tr class="alt">
              <th>Handler</th>
              <td>WebDAV</td>
            </tr>
            <tr>
              <th>Error Code</th>
              <td>0x00000000</td>
            </tr>

          </table>
        </div>
        <div id="details-right">
          <table border="0" cellpadding="0" cellspacing="0">
            <tr class="alt">
              <th>Requested URL</th>
              <td>http://portal.local.com:80/api/products/5</td>
            </tr>
            <tr>
              <th>Physical Path</th>
              <td>C:\_Dev\Applications\liteangular_portal\LiteAngular\api\products\5</td>
            </tr>
            <tr class="alt">
              <th>Logon Method</th>
              <td>Anonymous</td>
            </tr>
            <tr>
              <th>Logon User</th>
              <td>Anonymous</td>
            </tr>

          </table>
          <div class="clear"></div>
        </div>
      </fieldset>
    </div>
    <div class="content-container">
      <fieldset>
        <legend>Most likely causes:</legend>
        <ul>
          <li>The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.</li>
          <li>A request was sent to the server that contained an invalid HTTP verb.</li>
          <li>The request is for static content and contains an HTTP verb other than GET or HEAD.</li>
          <li>A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.</li>
        </ul>
      </fieldset>
    </div>
    <div class="content-container">
      <fieldset>
        <legend>Things you can try:</legend>
        <ul>
          <li>Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.</li>
          <li>Check the IIS log file to see which verb is not allowed for the request.</li>
          <li>Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click <a href="http://go.microsoft.com/fwlink/?LinkID=66439">here</a>.</li>
        </ul>
      </fieldset>
    </div>


    <div class="content-container">
      <fieldset>
        <legend>Links and More Information</legend>
        This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.
        <p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&amp;IIS70Error=405,0,0x00000000,7601">View more information &raquo;</a>
        </p>

      </fieldset>
    </div>
  </div>
</body>

</html>

I can make ajax calls to this api methods, so they should be fine. I've tried adding/removing Http ResponseType attributes to them all to no luck. Can some web/angular guru shed some light on this problem? Is it something in IIS? I found this: https://support.microsoft.com/en-us/kb/942051 and this http://www.c-sharpcorner.com/Blogs/47627/wepapi-http-error-405-0-method-not-allowed.aspx But messing with the IIS apphost config seems hackish. And I'm not familiar enough with it to make educated decision. EDIT: My config:

<customHeaders>
  <add name="Access-Control-Allow-Origin" value="*" />
  <add name="Access-Control-Allow-Headers" value="Content-Type, Accept, Authorization" />
  <add name="Access-Control-Allow-Credentials" value="true" />
  <add name="Access-Control-Allow-Methods" value="POST,GET,PUT,DELETE,OPTIONS" />
  <add name="Access-Control-Max-Age" value="1728000" />      
</customHeaders>

      

Thanks in advance!

P.S. It looks like the problem has to do with WebDAVModule: Notification MapRequestHandler Handler WebDAV Error Code 0x0000000

Anyone knows what it might be, though? Anyone?...

解决方案

It turned out removing WebDAV handler and WebDAVModule took care of the problem:

<handlers>
  <remove name="WebDAV" />
</handlers>
<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule" />
</modules>

这篇关于角$资源POST / PUT到的WebAPI 405不允许的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆