c#上传代码,拒绝访问

private void button2_Click(object sender, EventArgs e)
{

if (this.textBox3.Text == "" | this.textBox4.Text == "")
return;

WebClient MyClient = new WebClient();
string URL = this.textBox4.Text;
string FileName = this.textBox3.Text;
byte[] MyResponseArray = null;
try
{
MyResponseArray = MyClient.UploadFile(URL,FileName);
MessageBox.Show("文件上传成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception Err)
{
MessageBox.Show("文件上传失败!错误是:" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
MessageBox.Show("\n服务器的回复为:\n" + System.Text.Encoding.ASCII.GetString(MyResponseArray));
}
}
这段代码本地测试总是提示对路径****的访问被拒绝!

你上传到什么样的服务器!403错误!还是404错误!
403的错误需要设置服务器的配置或者自己写接收的代码。
404错误就是没找到!追问

- - 405 这是什么情况?

追答

405没遇到过!应该是权限的问题!你上传的时候,服务器应该是不让你上传!!你用的是什么服务器!

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-22
先看看相对于你的那个aspx页面,那个文件要上传到的文件夹是否存在,然后再看看权限设置。
相似回答