Server.MapPath访问在Azure上被拒绝 [英] Server.MapPath Access is denied On Azure

查看:37
本文介绍了Server.MapPath访问在Azure上被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#代码和电子表格light dll导出Excel.我正在尝试将图片插入excel,在本地计算机上一切正常,但在实时网站上却出现以下错误

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

我的c#代码.

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

当前我正在做的是手动提供IIS服务器上的访问权限,但这不是正确的方法,因为每次上传服务时,我都必须一次又一次地重做一次

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.

谢谢.

推荐答案

假设您正在使用云服务...

Assuming you are using Cloud services...

您应该为此使用本地存储( http://msdn.microsoft.com/zh-CN/library/windowsazure/ee758708.aspx ).

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

基本上;

  1. 在您的Cloud项目中,转到角色"的属性,然后选择本地存储".
  2. 添加一个新的本地存储,并为其命名,即"foo"和最大大小.如果这是用于临时处理而不是缓存,则可能需要勾选清除角色回收".
  3. 在您的代码中调用 RoleEnvironment.GetLocalResource("foo")以获取您可以使用的文件夹名称,然后执行类似 Path.Combine("path","Logo.png)来获取一个文件名,然后可以写入该文件名.
  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, i.e. "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.

这篇关于Server.MapPath访问在Azure上被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆