HTTPWeb请求“PUT”错误状态 405 IIS7 中不允许使用该方法
我的应用程序使用 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中。但这些解决方案都不适用于我的情况。
我在 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 应用程序/表单是使用 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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以解决此问题:
1) 从服务器完全卸载 WebDAV。您可以通过 Windows 添加/删除功能应用程序执行此操作。这将需要重新启动。
2)第二种解决方案很简单。 A) 转至 IIS 站点并单击模块。找到 WebDAV 模块并将其删除。
现在您仍然可以在其他站点上使用 WebDAV,而不会干扰此站点上的 PUT 方法。
B) 您可能需要找到正确的处理程序映射并添加 PUT 谓词。
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.
我不认为问题出在您的代码中...如果不允许 PUT 动词,则没有客户端能够 PUT 文件。它也没有说“未经授权”,如果是权限问题就会出现这种情况...我认为这仍然是 IIS 配置问题。查看此链接:
http://support.microsoft.com/kb/942051/en-我们
为了让事情变得更简单,你可以看看这个我听说对这件事很有用的工具:
http://www.microsoft.com/download/en/details .aspx?displaylang=en&id=21625
HTH。
I don't think the problem is in your code...if the PUT verb is not allowed, no client is going to be able to PUT files. It's not saying "Unauthorized" either, which would be the case if it were a permissions problem...I think this is still an IIS configuration one. Check this link out:
http://support.microsoft.com/kb/942051/en-us
To make things simpler on yourself, you might check out this tool that I've heard is good for this stuff:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21625
HTH.