2011-08-24 13 views
9

La mia app utilizza il metodo "Put" di HttpWebRequest per caricare file nelle app di asp.net ospitate in iis7. Ho avuto un errore Codice di stato 405 Metodo non consentito. Ho provato tutte le soluzioni che posso trovare nel forum per 2 giorni, inclusa la rimozione di webDav nei gestori, l'aggiunta del metodo "Put" nei gestori (come trovato in http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx), registrare nuovamente asp.net in iis. Ma nessuna delle soluzioni funziona nel mio caso.HTTPWebRequest "PUT" stato errore 405 Metodo non consentito in IIS7

corro traccia richieste non riuscite in IIS, e al di sotto è l'errore:

MODULE_SET_RESPONSE_ERROR_STATUS 
ModuleName StaticFileModule 
Notification 128 
HttpStatus 405 
HttpReason Method Not Allowed 
HttpSubStatus 0 
ErrorCode 2147942401 
ConfigExceptionInfo  
Notification EXECUTE_REQUEST_HANDLER 
ErrorCode Incorrect function. (0x80070001) 
    MODULE_SET_RESPONSE_ERROR_STATUS 
Warning  

ModuleName="StaticFileModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="405", HttpReason="Method Not Allowed", HttpSubStatus="0", ErrorCode="Incorrect function 

Ogni aiuto è molto apprezzato. Grazie. Il mio modulo/app asp.net è stato sviluppato utilizzando Visual Studio 2008 e pubblicato in iis 7.

-------------------------- ------------- UPDATE

Il codice per gestire HttpWebRequest (PUT) è il seguente: Ha preso il token di autenticazione dell'utente e lo ha verificato. Successivamente ha creato un ticket di autenticazione e la risposta all'utente.

 tokenSignature = false; 

     //To capture the tokenId 
     string MainString = Request.Headers.ToString(); 
     int FirstChr = MainString.IndexOf("*="); 
     MainString = MainString.Substring(FirstChr + 2); 
     int secondChr = MainString.IndexOf("%"); 
     tokenId = MainString.Substring(0, secondChr); 


     //to Write the received encrypted token into temporary folder 
     FileStream fs = new FileStream(AppsConfig.temp + tokenId, FileMode.Create); 
     BinaryWriter bw = new BinaryWriter(fs); 

     //Convert the listenerRequest into InputStream to write the token 
     Stream InputStream = Request.InputStream; 
     byte[] inData = new byte[32768]; 
     int bytesRead; 

     while ((bytesRead = InputStream.Read(inData, 0, inData.Length)) > 0) 
     { 
      bw.Write(inData, 0, bytesRead); 
     } 

     //close the connection that is used to write the token 
     bw.Close(); 
     fs.Close(); 

     //Read the temporary encrypted token (for decryption purposes) 
     fin = File.OpenRead(AppsConfig.temp + tokenId); 

     //To read the private key 
     Stream prSignKey = File.OpenRead(AppsConfig.privateKey); 
     PgpSecretKey pgpSec; 
     PgpSecretKeyRingBundle ringBundle = new PgpSecretKeyRingBundle(PgpUtilities.GetDecoderStream(prSignKey)); 

     //Get the company key Id and passphrase 
     String[] getText = new String[2]; 
     int no = 0; 
     TextReader readFile = new StreamReader(AppsConfig.keyFile); 

     do 
     { 
      getText[no] = readFile.ReadLine(); 
      no++; 
     } while (no < 2); 
     readFile.Close(); 
     long KeyId = Int64.Parse(getText[0]); 
     Char[] passwd = getText[1].ToCharArray(); 
     //Get the private key 
     pgpSec = ringBundle.GetSecretKey(KeyId); 
     PgpPrivateKey pgpPrivate = pgpSec.ExtractPrivateKey(passwd); 

     //Close all unnecessary connections 
     InputStream.Close(); 
     prSignKey.Close(); 
     readFile.Close(); 

     //Call the decrypt method to decrypt the token 
     decryptFile(fin, pgpPrivate, "original.xml", tokenId); 

     if (tokenSignature == true) 
     { 
      //Create the authentication cookie and add this cookie to the httpResponse 
      //This authentication cookie would be used to access the resource.aspx 
      HttpCookieCollection cc = Response.Cookies; 
      FormsAuthentication.SetAuthCookie(tokenId, false); 
      cc = Response.Cookies; 

     //remove the temporary file that was created earlier. 
      File.Delete(AppsConfig.temp + tokenId); 
      File.Delete(AppsConfig.temp + tokenId + ".bin"); 
     } 
     else 
     { 
      Server.Transfer("~/Error.aspx?errorMessage=" + "SignatureFailed"); 

     } 
+0

si prega di mostrare qualche codice sorgente ... esp. il "bersaglio" nella tua app asp.net che gestisce la richiesta PUT ... – Yahia

risposta

1

Non penso che il problema sia nel codice ... se il verbo PUT non è consentito, nessun client sarà in grado di inserire i file PUT. Non sta dicendo "Non autorizzato", il che sarebbe il caso se si trattasse di un problema di autorizzazioni ... Penso che questa sia ancora una configurazione IIS. Controllare questo link out:

http://support.microsoft.com/kb/942051/en-us

per rendere le cose più semplici su te stesso, si potrebbe verificare questo strumento che ho sentito è buono per questa roba:

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21625

HTH.

+0

Come hai detto, il problema non è nel mio codice in quanto sono in grado di farlo funzionare nella macchina di sviluppo con il filesystem di asp.net . È solo quando è pubblicato in iis, il problema appare. Ho provato i tuoi suggerimenti, ma finora non ho avuto fortuna. – iLoeng

+0

Entrambi i collegamenti sono interrotti, solo FYI. – ketura

13

ci sono un paio di percorsi troppo risolvere questo problema:

1) Disinstallare WebDAV dal server del tutto. Puoi farlo dall'app Aggiungi/Rimuovi funzionalità di Windows. Ciò richiederà un riavvio.

2) La seconda soluzione è semplice. A) Vai al sito IIS e fai clic sui moduli. Trova il modulo WebDAV e rimuovilo.

Ora puoi ancora utilizzare WebDAV sui tuoi altri siti e non interferire con il metodo PUT su questo sito.

enter image description here

B) Potrebbe essere necessario trovare la mappatura gestore corretto e aggiungere il verbo PUT.

+0

Ha funzionato come un incantesimo, grazie. – Doug

+0

ha funzionato per me :) – GreyCloud

Problemi correlati