IIS设置为windows集成验证后,在winform中使用WebClient上传文件失败?
把IIS设为允许匿名访问就不会出现问题
---------------------------------------------------------------------------------
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
----------------------------------------------------------------
winform中的upload事件:
private void FileUpload(string address, string category)
{
WebClient myWebClient = new WebClient();
myWebClient.UploadFile("http://localhost/cmp/test/winupload.aspx?category="+category,"POST",address);
}
----------------------------------------------------------------
winupload.aspx中:
private void Page_Load(object sender, System.EventArgs e)
{
string category = Request.Params["category"].ToString();
foreach( string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs(@"C:\Inetpub\wwwroot\cmp\Uploaded\"+ category + @"\" + file.FileName);
}
if( Request.Params["testKey"] != null )
{
Response.Write(Request.Params["testKey"]);
}
--------------------------------------------------------------------------------------