System.UnauthorizedAccessException尝试从服务器打开文件

时间:2015-06-26 15:46:50

标签: c# asp.net iis

尝试打开jpg文件时代码出错。

这是我的代码:

public ActionResult GetImage(string path, string title, string width, string height)
    {

        string imageFormat = path.Split('\\')[path.Split('\\').Length - 1].Split('.')[1];
        byte[] imageByteData = System.IO.File.ReadAllBytes(path);
    ....

我有这个例外

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Additional information: Acceso denegado a la ruta de acceso '\\server2008\Volumenes\intranet\Intranet 01\1645\2\6115753.jpg'.

我可以访问此文件并在Windows资源管理器中打开它,并将IIS_IUSRS应用于此文件夹。我试图配置IIS,但我不知道我需要配置。这个站点在DefaultAppPool中,并尝试将LocalServices和LocalSystem置于标识中,但这不起作用。

我读到我不需要在web.config中放任何代码,只是IIS中的配置。

感谢您的帮助

更新

我在ascx文件中有同样的错误

<%=Html.Action("GetUserImage", "Telefonos", new { path = imagen, clase="usrimg" })%>

在这种情况下,我有这个例外:

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

{System.UnauthorizedAccessException:拒绝访问'\ server2008 \ Volumenes \ intranet \ UserPictures \ image.jpg'

0 个答案:

没有答案
相关问题