我的应用程序使用 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 中运行失败的请求跟踪,下面是错误:
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");
}