2009-12-29 71 views
1

我遇到了一个问题,试图在IIS 6.0上使用ASP.NET MVC中的AJAX和jQuery。我尝试通过jQuery调用动作时收到403.1错误。有什么我必须添加到web.config为了支持这个?在IIS 6上使用AJAX与ASP.NET MVC 1.0

客户端代码

<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或其他可执行程序那不允许progra ms将被执行。

HTTP错误403.1 - 禁止:执行访问被拒绝。 Internet信息服务(IIS)


更新

达林正确pointend出来,它帮助,如果你添加DELETE动词.mvc延长,但是我现在的运行到了以下问题:

[HttpException(0X80004005):路径 '删除' 禁止] System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext的上下文)80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication + IExecutionStep.Execute()179系统.Web.HttpApplication.ExecuteSte P(IExecutionStep一步,布尔& completedSynchronously)

状态:405 - 不允许的方法

回答

4

当您在IIS与aspnet_isapi.dll注册.mvc扩展您需要启用DELETE动词:

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

+0

我照耀处下列动词: GET,HEAD,POST,DEBUG 我也选中“检查文件是否存在”。 – DarenMay 2009-12-29 15:42:20

+2

取消选中“验证文件是否存在”并将“DELETE”动词添加到列表中或选中“所有动词”。 – 2009-12-29 15:43:03

+0

感谢 - 这是很明显的,一旦你指出了这一点......现在,我得到一个HTTPException抛出: [HttpException(0x80004005的):路径“删除”是被禁止的。] System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext的背景下) +80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication + IExecutionStep.Execute()+179 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔型& completedSynchronously)+87 – DarenMay 2009-12-29 15:59:22

1

这是如何在代码中进行更改的:

class IISDirEntry 
    {  
public void SetProperty(string metabasePath, string propertyName, string newValue) 
     { 
      // metabasePath is of the form "IIS://servername/path" 
      try 
      { 
       DirectoryEntry path = new DirectoryEntry(metabasePath); 
       PropertyValueCollection propValues = path.Properties[propertyName]; 
       object[] propv = ((object[])propValues.Value); 
       int searchIndex = newValue.IndexOf(','); 

       int index = -1;     
       for (int i = 0; i < propv.Length; i++) 
       { 
        if (propv[i].ToString().ToLower().StartsWith(newValue.ToLower().Substring(0, searchIndex + 1))) 
        { 
         index = i; 
         break; 
        } 
       } 
       if (index != -1) 
       { 
        propv[index] = newValue; 
       } 
       else 
       { 
        List<object> proplist = new List<object>(propv); 
        proplist.Add(newValue); 
        propv = proplist.ToArray(); 
       } 

       path.Properties[propertyName].Value = propv; 
       path.CommitChanges(); 
       Console.WriteLine("IIS6 Verbs fixed."); 
      } 
      catch (Exception ex) 
      { 
       if ("HRESULT 0x80005006" == ex.Message) 
        Console.WriteLine(" Property {0} does not exist at {1}", propertyName, metabasePath); 
       else 
        Console.WriteLine("Failed in SetProperty with the following exception: \n{0}", ex.Message); 
      } 
     } 
} 

    public void ChangeIIS6Verbs() 
      { 
       if (IISVersion < 7.0) 
       { 
        IISDirEntry iisDirEntry = new IISDirEntry(); 
        string windir = Environment.GetEnvironmentVariable("windir"); 
        iisDirEntry.SetProperty("IIS://localhost/W3SVC/" + SiteIndex + "/ROOT", "ScriptMaps", 
        @".aspx," + Path.Combine(windir, @"\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll") + ",1,GET,HEAD,POST,DEBUG,DELETE"); 
       } 
      } 

有用的,如果需要配置上安装