HttpWebRequest的" PUT"错误状态405不允许的方法在IIS7 [英] HTTPWebRequest "PUT" error status 405 Method not allowed in IIS7

查看:797
本文介绍了HttpWebRequest的" PUT"错误状态405不允许的方法在IIS7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用HttpWebRequest的放的方法来上传文件到IIS7主办的asp.net应用程序。我有一个错误状态code 405不允许的方法。我已经试过了,我可以在论坛上找到2天,包括去除处理的WEBDAV所有的解决方案,将放的方法进入处理程序(如<一个发现href=\"http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx\">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中跟踪,以下是错误:

  MODULE_SET_RESPONSE_ERROR_STATUS
模块名StaticFileModule
通知128
的HTTPStatus 405
HTT preason不允许的方法
HttpSubStatus 0
错误code 2147942401
ConfigExceptionInfo
通知EXECUTE_REQUEST_HANDLER
错误code函数不正确。 (0x80070001)
    MODULE_SET_RESPONSE_ERROR_STATUS
警告模块名=StaticFileModule,通知=EXECUTE_REQUEST_HANDLER的HTTPStatus =405的Htt preason =不允许的方法,HttpSubStatus =0,错误code =不正确的函数

任何帮助是非常AP preciated。谢谢。
我的asp.net应用程序/形式使用Visual Studio 2008开发并发布在IIS 7中。

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

在code处理的HttpWebRequest(PUT)是如下:
它采取了用户身份验证令牌和验证。之后,它创造了一个身份验证票证和响应返回给用户。

  tokenSignature = FALSE;        //要捕获tokenId
        字符串MainString = Request.Headers.ToString();
        INT FirstChr = MainString.IndexOf(* =);
        MainString = MainString.Substring(FirstChr + 2);
        INT secondChr = MainString.IndexOf(%);
        tokenId = MainString.Substring(0,secondChr);
        //写接收加密令牌到临时文件夹
        的FileStream FS =新的FileStream(AppsConfig.temp + tokenId,FileMode.Create);
        的BinaryWriter体重=新的BinaryWriter(FS);        //将listenerRequest成的InputStream写令牌
        流的InputStream = Request.InputStream;
        字节[] = INDATA新的字节[32768]
        INT读取动作;        而((读取动作= InputStream.Read(INDATA,0,inData.Length))大于0)
        {
            bw.Write(INDATA,0,读取动作);
        }        //关闭用于写令牌连接
        bw.Close();
        fs.Close();        //读取临时加密令牌(用于解密的目的)
        鳍= File.OpenRead(AppsConfig.temp + tokenId);        //读取私钥
        流prSignKey = File.OpenRead(AppsConfig.privateKey);
        PgpSecretKey pgpSec;
        PgpSecretKeyRingBundle ringBundle =新PgpSecretKeyRingBundle(PgpUtilities.GetDe coderStream(prSignKey));        //获取公司密钥ID和密码
        的String [] =的getText新的String [2];
        int无= 0;
        TextReader的READFILE =新的StreamReader(AppsConfig.keyFile);        做
        {
            的getText [无] = readFile.ReadLine();
            无++;
        }而(无2);
        readFile.Close();
        长的keyid = Int64.Parse(gettext的[0]);
        的char [] = passwd中的getText [1] .ToCharArray();
        //获取私钥
        pgpSec = ringBundle.GetSecretKey(KEYID);
        PgpPrivateKey pgpPrivate = pgpSec.ExtractPrivateKey(passwd)的;        //关闭所有不必要的连接
        InputStream.Close();
        prSignKey.Close();
        readFile.Close();        //调用解密方法解密令牌
        decryptFile(翅,pgpPrivate,original.xml,tokenId);        如果(tokenSignature ==真)
        {
            //创建身份验证cookie和这个cookie添加到HTT presponse
            //这验证cookie将用于访问resource.aspx
            HttpCookieCollection CC = Response.Cookies;
            FormsAuthentication.SetAuthCookie(tokenId,FALSE);
            CC = Response.Cookies;        //删除之前创建的临时文件。
            File.Delete(AppsConfig.temp + tokenId);
            File.Delete(AppsConfig.temp + tokenId +.BIN);
        }
        其他
        {
            Server.Transfer的(〜/ Error.aspx的errorMessage =+SignatureFailed);        }


解决方案

有一对夫妇路线过于解决这个问题:

1)卸载的WebDAV从完全的服务器。您可以从Windows添加/删除功能的应用程序做到这一点。这将需要重新启动。

2)第二溶液是简单的。 A)进入IIS网站,然后单击模块。查找WebDAV模块并将其取出。

现在,你仍然可以使用您的其他网站的WebDAV,而不是与本网站的PUT方法干扰。

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

My app use HttpWebRequest "Put" method to upload file into the asp.net apps hosted in iis7. I had an error Status Code 405 Method Not Allowed. I've tried all solutions that I can found in the forum for 2 days, including removing the webDav in handlers, adding "Put" method into the handlers ( as found in http://blogs.msdn.com/b/joseph_fultz/archive/2009/07/23/enabling-the-put-verb-with-handlers-and-iis-7-0.aspx), re-register asp.net into iis. But none of the solutions work in my case.

I run Failed Request Tracing in iis, and below is the error:

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

Any help is highly appreciated. Thanks. My asp.net apps/form was developed using Visual Studio 2008 and published in iis 7.

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

The code to handle the HttpWebRequest (PUT) is below: It took the user authentication token and verify it. After that it created a authentication ticket and response back to user.

     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");

        }

解决方案

There are a couple routes too fix this problem:

1) Uninstall WebDAV from the server entirely. You can do this from the Windows Add/Remove features app. This will require a reboot.

2) The second solution is simple. A) Go to the IIS Site and click modules. Find the WebDAV module and remove it.

Now you can still use WebDAV on your other sites and not interfere with the PUT method on this site.

B) You may need to find the correct handler mapping and add the PUT verb.

这篇关于HttpWebRequest的&QUOT; PUT&QUOT;错误状态405不允许的方法在IIS7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆