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

iLo*_*eng 9 asp.net iis put httpwebrequest

我的应用程序使用HttpWebRequest"Put"方法将文件上传到iis7中托管的asp.net应用程序.我有一个错误状态代码405方法不允许.我已经试过了,我可以在论坛中发现2天,包括去除处理WebDAV的所有解决方案,将"放"的方法进入处理程序(如发现http://blogs.msdn.com/b/joseph_fultz/存档/ 2009/07/23 /使最把动词与-处理器和-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
Run Code Online (Sandbox Code Playgroud)

任何帮助都非常感谢.谢谢.我的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");

        }
Run Code Online (Sandbox Code Playgroud)

Luc*_*cas 13

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

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

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

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

在此输入图像描述

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


Chr*_*ens 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。