c# - Windows Azure Cloud Service - Access to deployed xml file denied -


i have mvc app runs fine on premise, runs fine on azure web sites. when deployed cloud service have access denied problems accessing xml files.

these xml files bits of data required application determine settings within application.

there large number of these under hierarchical folder structure, idea each of these processed allow inheritance of these settings need within application. anyway largely irrelevant @ end of day these xml files stored in folder under web root.

the build action properties of xml files set content deployed publish. in fact have rdp'd onto cloud service vm check xml files getting deployed , can confirm are.

however whenever application tried read 1 of these files following access denied error.

access path 'e:\sitesroot\0\templates\applications\controlproperties.xml' denied.

(note : not hard coded path assumed answer below, using httpcontext.current.server.mappath determine physical path of file relative web root)

this standard access denied error indicating application not have access read file.

now if rdp again machine , grant full access particular file (just diagnostic purposes!), application works fine without throwing error. proves access issue.

the question is, these simple xml files deployed project, , don't want having set file permissions on each deployment. wrong.

so trying understand why part of standard deploy cloud service not have access read these deployed xml files, , interested in proper solution. i.e. either permission settings maybe deployed solution, or maybe there better alternative approach problem.

in terms of code using read xml file, using xmlserializer deserialize contents of file object. (as below)

 public static t deserialise(string settingsfile)     {         using (var fs = new filestream(settingsfile, filemode.open))         {             var sr = new xmlserializer(typeof (t));             var obj = (t) sr.deserialize(fs);             fs.close();             return obj;         }     } 

i understand there local storage web roles, , fine me use if wanted able read , write storage part of application. these configuration settings files need deployed along application.

in end problem turned out file access method. using filestream open contents of file, , when running under elevated role permissions getting accessed denied error.

however changing code read file contents string first, able avoid error.

    public static t deserialise(string settingsfile)     {         var filecontents = file.readalltext(settingsfile);         using (var fs = new memorystream(encoding.ascii.getbytes(filecontents)))         {             var sr = new xmlserializer(typeof (t));             var obj = (t) sr.deserialize(fs);             fs.close();             return obj;         }     } 

not sure why filestream method needed these permissions, above solution works me in scenario.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -