2011-08-24 28 views
9

Ứng dụng HttpWebRequest "Đặt" của ứng dụng của tôi để tải tệp lên ứng dụng asp.net được lưu trữ trong iis7. Tôi đã gặp lỗi Mã trạng thái 405 Phương pháp không được phép. Tôi đã thử tất cả các giải pháp mà tôi có thể tìm thấy trong diễn đàn trong 2 ngày, bao gồm xóa webDav trong trình xử lý, thêm phương thức "Đặt" vào trình xử lý (như được tìm thấy trong http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx), đăng ký lại asp.net vào iis. Nhưng không có giải pháp nào hoạt động trong trường hợp của tôi.Trạng thái lỗi "PUT" HTTPWebRequest 405 Phương thức không được phép trong IIS7

Tôi chạy Failed Request Tracing trong IIS, và dưới đây là lỗi:

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 

Bất kỳ trợ giúp được đánh giá cao. Cảm ơn. Ứng dụng/mẫu asp.net của tôi đã được phát triển bằng Visual Studio 2008 và được xuất bản bằng iis 7.

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

Mã để xử lý HttpWebRequest (PUT) dưới đây: Mã thông báo xác thực người dùng và xác minh mã đó. Sau đó nó tạo ra một vé xác thực và trả lời lại cho người dùng.

 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

vui lòng hiển thị một số mã nguồn ... esp. "mục tiêu" trong ứng dụng asp.net của bạn xử lý yêu cầu PUT ... – Yahia

Trả lời

1

Tôi không nghĩ rằng vấn đề là trong mã của bạn ... nếu động từ PUT là không được phép, không có khách hàng đang xảy ra để có thể đưa các tập tin. Nó không nói "Không được ủy quyền", hoặc, đó sẽ là trường hợp nếu nó là một vấn đề quyền ... Tôi nghĩ rằng đây vẫn là một cấu hình IIS một. Kiểm tra liên kết này ra:

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

Để làm cho mọi việc đơn giản hơn về bản thân, bạn có thể kiểm tra công cụ này mà tôi đã nghe nói là tốt cho công cụ này:

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

HTH.

+0

Như bạn đã đề cập, vấn đề không có trong mã của tôi vì tôi có thể làm cho nó hoạt động trong máy dev với hệ thống tệp asp.net . Nó chỉ khi nó được xuất bản trong iis, vấn đề xuất hiện. Tôi đã thử đề xuất của bạn, nhưng không có may mắn cho đến nay. – iLoeng

+0

Cả hai liên kết đều bị hỏng, chỉ là FYI. – ketura

13

Có một vài tuyến đường quá khắc phục vấn đề này:

1) Gỡ bỏ WebDAV từ máy chủ hoàn toàn. Bạn có thể thực hiện việc này từ ứng dụng Windows Add/Remove features. Điều này sẽ yêu cầu khởi động lại.

2) Giải pháp thứ hai rất đơn giản. A) Vào trang IIS và bấm vào các mô-đun. Tìm mô-đun WebDAV và loại bỏ nó.

Bây giờ bạn vẫn có thể sử dụng WebDAV trên các trang web khác của bạn và không can thiệp vào phương pháp PUT trên trang web này.

enter image description here

B) Bạn có thể cần phải tìm ánh xạ xử lý chính xác và thêm động từ PUT.

+0

Làm việc như một say mê, cảm ơn bạn. – Doug

+0

Đã làm việc cho tôi :) – GreyCloud

Các vấn đề liên quan