2009-12-29 3 views
1

Je rencontre un problème en essayant d'utiliser AJAX et jQuery avec ASP.NET MVC sur IIS 6.0. Je reçois une erreur 403.1 lorsque j'essaie d'invoquer une action via jQuery. Y a-t-il quelque chose que je dois ajouter au web.config pour supporter cela?Utilisation d'AJAX avec ASP.NET MVC 1.0 sur IIS 6

Code client

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

Code Serveur

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

Erreur

Vous avez essayé d'exécuter un CGI, ISAPI, ou tout autre programme exécutable à partir d'un répertoire cela ne permet pas progra ms à exécuter.

Erreur HTTP 403.1 - Interdit: L'accès à l'exécution est refusé. Internet Information Services (IIS)


Mise à jour

Darin pointend à juste titre que cela aide si vous ajoutez le verbe SUPPRIMER à .mvc extension, mais je une course maintenant dans la question suivante:

[HttpException (0x80004005). Chemin 'DELETE' est interdit] System.Web.HttpMethodNotAllowedHandler.ProcessRequest (HttpContext contexte) +80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication + IExecutionStep.Execute() +179 système .Web.HttpApplication.ExecuteSte p (étape IExecutionStep, Boolean & completedSynchronously)

Statut: 405 - Méthode non autorisée

Répondre

4

Lorsque vous enregistrez l'extension .mvc avec aspnet_isapi.dll dans IIS, vous devez activer le verbe DELETE:

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

+0

J'enterd les verbes suivants: GET, HEAD, POST, DEBUG J'ai aussi décoché "Verify ce fichier existe". – DarenMay

+2

Décochez la case 'Vérifier que le fichier existe' et ajoutez le verbe' DELETE' à la liste ou cochez 'Tous les verbes'. Merci –

+0

- qui était assez évident une fois que vous montrai ... Maintenant, je reçois un HttpException jeté: [HttpException (0x80004005): Chemin 'DELETE' est interdite.] System.Web.HttpMethodNotAllowedHandler.ProcessRequest (contexte HttpContext) +80 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication + IExecutionStep.Execute() +179 System.Web.HttpApplication.ExecuteStep (étape IExecutionStep, Boolean & completedSynchronously) +87 – DarenMay

1

Voici comment changer cela en code:

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

Utile si nécessaire de configurer lors de l'installation

Questions connexes