简体   繁体   中英

Server.MapPath Access is denied On Azure

I am exporting an excel using c# code and spreadsheetlight dll. I am trying to insert a picture into excel, everything works well on local machine but on live web site it gives following error

Access to the path 'F:\sitesroot\0\Images\Logo.png' is denied

My c# code.

string filePath = Server.MapPath("~/Images/Logo.png");
SLPicture pic = new SLPicture(filePath); //SLPicture - An inbuilt class for inserting image

Currently what I am doing is manually providing access rights on IIS server but which is not the correct way to go since each time I upload the service I have to redo that again and again

Any expert advice - How I can provide access right through code? Or How to get rid of this error.

Thanks.

Assuming you are using Cloud services...

You are supposed to use Local Storage for this ( http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx ).

Basically;

  1. In your Cloud project, go to the properties for the Role and select Local Storage.
  2. Add a new local storage and give it a name, ie "foo" and a maximum size. If this is for temporary processing rather than caching, you probably want to tick "Clean on role recycle".
  3. In your code call RoleEnvironment.GetLocalResource("foo") to get the folder name you can use and then do something like Path.Combine("path","Logo.png") to get a file name which you can then write to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM