提问人:user3075373 提问时间:3/8/2016 最后编辑:doobopuser3075373 更新时间:3/8/2016 访问量:259
ASP.NET AJAX PUT 方法不允许和未经授权
ASP.NET AJAX PUT Method not allowed and Unauthorized
问:
当我向我的文件发送ajax请求时,我遇到了错误,但是当我将其添加到我的文件中时,我有text.aspx
405 (Method not allowed)
web.config
401 (Unauthorized)
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/> <!-- ADD THIS -->
</modules>
</system.webServer>
</configuration>
在我的测试下方.aspx.cs文件和测试.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();
}
}
}
测试 .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赞
Spluf
3/8/2016
#1
此外,将此行添加到模块后面的配置中:
<handlers>
<remove name="WebDAV" />
</handlers>
0赞
user3075373
3/8/2016
#2
我们可以在 *.aspx 路径中添加请求限制PUT, DELETE
但是在我的 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>
下一个:从子级响应父级访问状态
评论