远程服务器返回错误:(405)方法不允许。

4
我知道这是一个普遍面临的问题,但我遇到了一个不同的情况。 我将在此处解释场景。
我在一个解决方案中创建了两个不同的项目。我想用于保存即上传的图像包含文件夹位于这些项目之外,但在同一解决方案下。 实际上,我在该文件夹的 IIS 服务器上创建了虚拟目录(我的文件服务器)。
以下是我的代码。
private void SaveData()
        {


            string filename = Path.GetFileName(ImageUpload.PostedFile.FileName);
            string servpath = Server.MapPath(ConfigurationManager.AppSettings["TempFolder"]);
            ImageUpload.SaveAs(servpath + filename);
            string remoteServerPath = ConfigurationManager.AppSettings["ProductImagesPath"] + filename;
            try
            {

                WebClient client = new WebClient();

                client.UploadFile(remoteServerPath, servpath + filename);
            }
            catch (Exception ex)
            {
                throw ex;

            }
            objProductsCustom.ProductName = txtProductName.Text;
            objProductsCustom.ProductDiscription = txtAddDiscription.Text;
            objProductsCustom.ProductPrice = txtPrice.Text;
            objProductsCustom.Quantity = txtQuantity.Text;
            objProductsCustom.ImagePath = "servpath" + filename;
            int productID = objProductsManager.CreatProduct(objProductsCustom);

        }

在try-catch语句中,我发现了"远程服务器返回错误:(405)方法不允许"的错误。我被困住了。

编辑 这是远程服务器路径:

http://localhost/ProductImages/untitled.bmp

这是我要上传到远程服务器路径的文件:

C:\Documents and Settings\saltaf\My Documents\Visual Studio 2010\Projects  \OnlineShoppingSystem\OnlineShoppingSiteAdminPanel\Temp\Images\untitled.bmp

这是我要调用的代码:

 webclient.UploadFile(http://localhost/ProductImages/untitled.bmp,C:\Documents and  Settings\saltaf\My Documents\Visual Studio 2010\Projects\OnlineShoppingSystem\OnlineShoppingSiteAdminPanel\Temp\Images\untitled.bmp)

这似乎是一个打字错误,但问题并不在于此。让我们专注于问题本身。 - muhammad kashif
前往IIS,然后打开目录浏览并启用它,这应该可以解决问题。 - MethodMan
当您调用client.UploadFile时,remoteServerPath的值是什么?该URL上有哪些应用程序/网站/其他站点?我怀疑您正在尝试上传到不支持POST的HTTP URL,但由于不清楚您的服务器是什么,很难确定。 - Dan Puzey
我刚刚编辑了我的问题,请您查看一下。 - Saquib Altaf
1
你的意思是405方法不允许吗? - Rawling
显示剩余2条评论
1个回答

0

你尝试过检查保存文件的文件夹的权限吗?应该包括'IIS_IUSRS'配置文件(也应该具有目标文件夹的写入权限)。

希望这可以帮到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接