Jquery – Using AJAX with ASP.NET MVC 1.0 on IIS 6

asp.net-mvciis-6jquery

I am running into a problem trying to use AJAX and jQuery with ASP.NET MVC on IIS 6.0. I receive a 403.1 error when I attempt to invoke an action via jQuery. Is there anything I must add to the web.config in order to support this?

Client Code

<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>

Server Code

[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);
}

Error

You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.

HTTP Error 403.1 – Forbidden: Execute access is denied.
Internet Information Services (IIS)


Update

Darin correctly pointend out that it helps if you add the DELETE verb to .mvc extension, however I an now running into the following issue:

[HttpException (0x80004005): Path 'DELETE' is forbidden.] System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext context) +80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Status: 405 – Method not allowed

Best Answer

When you register the .mvc extension with aspnet_isapi.dll in IIS you need to enable the DELETE verb:

alt text http://support.citrix.com/article/html/images/CTX104183-1.gif