We have a custom CMS site in which the admin can make a change to the _Layout.cshtml (since they are making lots of changes). The site was hosted in Azure Web Sites, but now we are moving it to Cloud Services.
Now, the admin panel is reading and showing the contents of _Layout.cshtml (actually, all of the files in the ~/Views/Shared folder can be edited), but when the application is trying to write to a file, it throws this error: Access to the path 'F:sitesrootViewsoasShared_Layout.cshtml' is denied.
We are working on a new way to edit the layout files, but before we get there, we need a quick fix! I am using this method to write to the file: System.IO.File.WriteAllText(path, fileContents);
Locally, in the windows azure emulator, this is working correctly, but not when it's hosted on Azure.
Thanks!
First of all, I have to say there will be some problems even though you can update your _Layout.cshtml
file.
If you have more than one instances of your web role, once admin changed the page, it will only update the file one that instance, but others will NOT be changed by default. You have to somehow sync them.
If your instance had been moved to another virtual machine, for some reasons such as hardware failure or virtual machine resource reallocation, all changes your admin made will be lost.
So I strongly recommend to amend your implementation. How about save the change part into BLOB, table or database, then when the page was rendered you retrieve the content from DB. I think this would be better than just modify the page itself.
HTH.