【发布时间】:2009-12-29 15:33:58
【问题描述】:
我在 IIS 6.0 上尝试将 AJAX 和 jQuery 与 ASP.NET MVC 一起使用时遇到了问题。当我尝试通过 jQuery 调用操作时收到 403.1 错误。为了支持这一点,我必须在 web.config 中添加什么内容吗?
客户端代码
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
function deleteRecord(recordId) {
// Perform delete
$.ajax(
{
type: "DELETE",
url: "/Financial.mvc/DeleteSibling/" + recordId,
data: "{}",
success: function(result) {
window.location.reload();
},
error: function(req, status, error) {
alert("Unable to delete record.");
}
});
}
</script>
<a onclick="deleteRecord(<%= sibling.Id %>)" href="JavaScript:void(0)">Delete</a>
服务器代码
[AcceptVerbs(HttpVerbs.Delete)]
public virtual ActionResult DeleteSibling(int id)
{
var sibling = this.siblingRepository.Retrieve(id);
if (sibling != null)
{
this.siblingRepository.Delete(sibling);
this.siblingRepository.SubmitChanges();
}
return RedirectToAction(this.Actions.Siblings);
}
错误
您试图从不允许执行程序的目录中执行 CGI、ISAPI 或其他可执行程序。
HTTP 错误 403.1 - 禁止:执行访问被拒绝。 互联网信息服务 (IIS)
更新
Darin 正确地指出,如果您将 DELETE 动词添加到 .mvc 扩展名,它会有所帮助,但是我现在遇到了以下问题:
[HttpException (0x80004005): 路径'DELETE'被禁止。] System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext context) +80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179 System .Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
状态:405 - 方法不允许
【问题讨论】:
标签: asp.net-mvc iis-6 jquery