0

I have made an api using Webapi 2. It's controller calls to service which calls to repository.

I have Post method where in repository I am executing a url to get a document stream which I am eventually saving into a location HostingEnvironment.MapPath("~/Uploads/") + documentname;.

This location is used in repository code to save the stream into file using the location and accessing through this location only:

using (var fileStream = new FileStream(document.DocumentPath, FileMode.Open, FileAccess.Read))
{
    ....
}

I need to do this because other api call needs to use this file's stream again for further processing.

Everything works fine when I have an instance of server running in my local machine, however when this service is hosted into a server I am receiving a 500 Internal Server Error. FileNotFoundException.

I do not have the access to server So I couldn't figure what could actually be the cause for it. My thinking is that my local file system is accessible to service, but I might need to have some extra permissions setup in server. Any thoughts on this would be really appreciated.

Pushpendra
  • 1,694
  • 14
  • 27

2 Answers2

1

Can you try saving the file in the App_Data folder? If you don't have that folder, you can create it by right-clicking on the project > Add Folder>ASP.NET folder>App_Data.

You can access the folder by (assuming you created folder 'uploads'):

string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/uploads");

alltej
  • 6,787
  • 10
  • 46
  • 87
  • I did that. It still didn't work. It should have been writable. I am using temp folder from .net framework to accomplish my task. Thanks for your suggestion though :) – Pushpendra Aug 17 '16 at 04:19
0

Adding IIS_IUSRS to that folder and setting the relevant permissions should do the job. Hope this helps.