The remote server responded with an error: (405) Valid method

I know this is a common problem facing, but I get this problem with a different scenario. i'm going to explain the script here

I created two different projects in the solution. The image containing the folder that I want to use for saving, ie loading is outside of these above projects, but under the same solution. Actually I created virtual directly (My File Server) on the IIS server of this folder

here is my code.

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); } 

Where in try-catch I found that β€œThe remote server responded with an error: (405)β€œ Valid method. ”Error. I'm stuck.

EDIT This is the remoteserverpath path:

 http://localhost/ProductImages/untitled.bmp 

And this is the file that I upload to remoteserverpath:

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

And this is my call:

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

Did you try to check permissions for the folder where you save the file? It must include the IIS_IUSRS profile (which must also have WRITE permission for the destination folder).

Hope this helps.

0
source

Source: https://habr.com/ru/post/1441807/


All Articles