代码之家  ›  专栏  ›  技术社区  ›  Ian Boyd

IIS:405(不允许方法)在发布到默认页时

  •  3
  • Ian Boyd  · 技术社区  · 14 年前

    POST

    POST http://errorreporting.example.com/ HTTP/1.1
    

    302 将客户端重定向到 岗位 我该走了。这个 default.asp which is the technique Microsoft recommends ),通过执行 Redirect

    默认.asp:

    <%
       Response.Redirect "SubmitError.ashx"
    %>
    

    当我只是 服务器:

    GET http://errorreporting.example.com/ HTTP/1.1
    

    我从服务器得到预期的响应:

    HTTP/1.1 302 Object moved
    Server: Microsoft-IIS/5.0
    Location: SubmitError.ashx
    ...
    

    到服务器:

    服务员对我很生气:

    HTTP/1.1 405 Method not allowed
    Connection: close
    Allow: OPTIONS, TRACE, GET, HEAD
    ...
    

    我想要那个 能够重定向 客户 提交适当的 URL 统一资源定位地址 . 当然,这是因为URL可能(即已经)更改:

    • http://errorreporting.example.com/SubmitError.asp
    • http://errorreporting.example.com/SubmitError.aspx
    • http://errorreporting.example.com/SubmitError.ashx
    • http://errorreporting.example.com/ErrorReporting/Submit.ashx
    • http://errorreporting.example.com/submiterror.php
    • http://errorreporting.example.com/submit/submiterror.ashx

    注意 :如果我更改 要包含文档位置:

    /* SErrorReportingUrl = 'http://www.example.com:8088/ErrorReporting/SubmitError.ashx';
       SErrorReportingUrl = 'http://www.example.com/ErrorReporting/SubmitError.ashx';
       SErrorReportingUrl = 'http://errorreporting.example.com:8088/ErrorReporting/SubmitError.ashx';
       SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx';
       SErrorReportingUrl = 'http://errorreporting.example.com';
       SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx'; 
    */
       SErrorReportingUrl = 'http://errorreporting.example.com/submit/SubmitError.ashx';
    

    HTTP/1.1 200 OK
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Ian Boyd    14 年前

    结果是让IIS支持 POST 没什么用。

    XMLHttpRequest 执行 岗位 s。几乎每一个 XMLHttpRequest请求 在外面( GET 岗位

    这个 W3C's XMLHttpReqest specification 表示应遵循重定向并重新发出请求:

    (是的 same origin 例如, 无限循环预防措施 这个 same-origin request event rules .

    注意:HTTP对用户提出了要求 关于保存 这个 request method request entity body 要求通知最终用户

    以及 here's a site 您可以在浏览器的 XmlHttpRequest


    最后,我将围绕一个 IIS 虫子,还有 bug,让我的“默认”页面 302 redirect 会,但会回来 200 OK 取而代之的是:

    HTTP/1.1 200行
    Connection: close
    Date: Sun, 27 Jun 2010 13:28:14 GMT
    Server: Microsoft-IIS/6.0
    Location: http://errorreporting.example.com/submit/SubmitError.ashx
    Content-Length: 92
    Content-Type: text/html
    Cache-control: private

    <HTML><BODY>This content has moved <A href="submit/SubmitError.ashx">here.</A></BODY></HTML>
    

        2
  •  0
  •   maccaroo    4 年前

    我正在Express/Node上运行Vue.js。后端在服务器端口3300上运行,但我们不想公开它。

    Application Request Writing URL Rewrite )然后添加了一个入站规则来重写要表达的后端请求,但我一直得到405(不允许使用方法)。

    Stefano Scerra's Blog .

    下面是我的最后一个web.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
              </conditions>
              <action type="Rewrite" url="/" />
            </rule>
            <rule name="api" stopProcessing="true">
                <match url="^api/(.*)$" />
                <action type="Rewrite" url="http://10.1.1.217:3300/{R:1}" logRewrittenUrl="true" />
            </rule>
          </rules>
        </rewrite>
            <tracing>
                <traceFailedRequests>
                    <add path="*">
                        <traceAreas>
                            <add provider="WWW Server" areas="Filter" verbosity="Verbose" />
                        </traceAreas>
                        <failureDefinitions timeTaken="00:00:00" statusCodes="100-999" />
                    </add>
                </traceFailedRequests>
            </tracing>
      </system.webServer>
    </configuration>