首页 文章

HTTPWebRequest“PUT”错误状态405 IIS7中不允许使用的方法

提问于
浏览
9

我的应用程序使用HttpWebRequest "Put"方法将文件上传到iis7中托管的asp.net应用程序 . 我有一个错误状态代码405方法不允许 . 我已经尝试了在论坛中找到的所有解决方案2天,包括删除处理程序中的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中 . 但在我的案例中,没有一个解决方案可行 .

我在iis中运行Failed Request Tracing,以下是错误:

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应用程序/表单是使用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");

        }

2 回答

  • 1

    有几条路线也解决了这个问题:

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

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

    现在,您仍然可以在其他站点上使用WebDAV,而不会干扰此站点上的PUT方法 .

    enter image description here

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

  • 13

    我不认为问题出在你的代码中......如果不允许PUT动词,那么没有客户端能够PUT文件 . 它也不是说“未授权”,如果它是权限问题就是这种情况......我认为这仍然是一个IIS配置 . 检查此链接:

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

    为了让自己更简单,你可以看看我听说这个工具有用的工具:

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

    HTH .

相关问题