2016-03-08 39 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> 
相关问题