2011-08-24 106 views
9

我的应用程序使用HttpWebRequest“Put”方法将文件上传到托管在iis7中的asp.net应用程序中。我有一个错误状态码405方法不允许。我已经尝试了在论坛中可以找到的所有解决方案,包括删除处理程序中的webDav,将“Put”方法添加到处理程序中(如http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx中所示),将asp.net重新注册为iis。但是没有一个解决方案适用于我的情况。HTTPWebRequest“PUT”错误状态405 IIS7中不允许的方法

我运行失败请求在IIS跟踪,以下是错误:

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 

任何帮助,高度赞赏。谢谢。 我的asp.net apps/form是使用Visual Studio 2008开发的,并发布在iis 7中。

-------------------------- -------------更新

处理HttpWebRequest(PUT)的代码如下: 它采取了用户身份验证令牌并验证它。之后,它创建了一个认证票据和回复给用户。

 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

请显示一些源代码... esp。在你的asp.net应用程序中处理PUT请求的“目标”... – Yahia

回答

1

我不认为问题出现在您的代码中......如果PUT动词不被允许,则没有客户端将能够PUT文件。它并不是说“未经授权”,如果是权限问题,情况会是这样的......我认为这仍然是一个IIS配置。检查此链接了:

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

为了让事情变得更简单的自己,你可以看看这个工具,我已经听到好这个东西:

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

HTH。

+0

正如你所提到的,这个问题不在我的代码中,因为我能够使用asp.net文件系统在开发机器中工作。只有当它在iis上发布时,才会出现问题。我尝试了你的建议,但目前还没有运气。 – iLoeng

+0

这两个链接都被打破,仅供参考。 – ketura

13

有一对夫妇的路线过于解决这个问题:从服务器

1)卸载WebDAV的完全。您可以从Windows添加/删除功能应用程序执行此操作。这将需要重新启动。

2)第二种解决方案很简单。 A)转到IIS站点并单击模块。找到WebDAV模块并将其删除。

现在,您仍然可以在其他网站上使用WebDAV,并且不会干扰本网站上的PUT方法。

enter image description here

B)您可能需要找到正确的处理程序映射,并添加PUT动词。

+0

像魅力一样工作,谢谢。 – Doug

+0

为我工作:) – GreyCloud