2016-03-08 75 views
2

當我發送Ajax請求我text.aspx文件,然後我有錯誤405 (Method not allowed)但是當我加入這個我web.config然後我有401 (Unauthorized)ASP.NET AJAX PUT不允許的方法和未經授權的

<configuration> 
<system.webServer> 
<validation validateIntegratedModeConfiguration="false"/> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule"/> <!-- ADD THIS --> 
    </modules> 
</system.webServer> 
</configuration> 

下面我test.aspx.cs文件和Test.aspx的

using System; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class Test : System.Web.UI.Page { 

    public string method; 
    public int age = 24; 

    protected void Page_Load(object sender, EventArgs e) { 
     method = Request.ServerVariables["request_method"]; 
     if(method=="PUT") { 
      Response.Clear(); 
      Response.Write("PUTEM JE"); 
      Response.End(); 
     } 
    } 
} 

Test.aspx的

<%@ Page Language="C#" CodeFile="test.aspx.cs" inherits="Test" %> 
<body> 
    <script> 
    var xhr = new XMLHttpRequest(); 
    xhr.onload = function(e) { 
     console.log(e); 
    } 
    xhr.open('put', '/moja/test.aspx', true); 
    xhr.send(); 
    </script> 
</body> 
</html> 

有人能告訴我什麼是錯的?

回答

0

也是這一行添加到您的配置模塊後:

<handlers> 
    <remove name="WebDAV" /> 
</handlers> 
+0

仍然不工作。 – user3075373

0

實際上我找到了解決辦法! :) enter image description here

我們可以只添加PUT, DELETE在*的.aspx路徑

內請求限制但不工作沒有這在我的web.config:

<configuration> 
<system.webServer> 
<security> 
    <requestFiltering> 
     <verbs allowUnlisted="false"> 
      <add verb="GET" allowed="true" /> 
      <add verb="POST" allowed="true" /> 
      <add verb="DELETE" allowed="true" /> 
      <add verb="PUT" allowed="true" /> 
     </verbs> 
    </requestFiltering> 
</security> 
    <handlers> 
     <remove name="PageHandlerFactory-ISAPI-2.0" /> 
     <remove name="PageHandlerFactory-Integrated-4.0" /> 
     <remove name="PageHandlerFactory-Integrated" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" responseBufferLimit="0" /> 
     <add name="PageHandlerFactory-Integrated" path="*.aspx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" /> 
     <add name="PageHandlerFactory-Integrated-4.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" /> 
     <add name="PageHandlerFactory-ISAPI-2.0" path="*.aspx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0" /> 
    </handlers> 
</system.webServer> 
<system.web> 
    <authentication mode="None" /> 
</system.web> 
</configuration>