Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.UnauthorizedAccessException尝试从服务器打开文件_C#_Asp.net_Iis - Fatal编程技术网

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

C# System.UnauthorizedAccessException尝试从服务器打开文件,c#,asp.net,iis,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.

我在尝试打开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\U IUSRS应用于此文件夹。我试图配置IIS,但我不知道我需要配置什么。此站点位于DefaultAppPool中,并尝试将LocalServices和LocalSystem置于identity中,但这不起作用

我读到我不需要在web.config中添加任何代码,它只是IIS中的一个配置

谢谢你的帮助

更新:

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

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

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

我不会将此作为答案发布,因为这更像是一个建议,很有可能不是问题……但我最近在一个项目中工作,因为我试图创建一个子目录来保存fi,所以引发了此异常您可以从Windows资源管理器中打开,但它是由其他用户运行的。此外,默认情况下,安全权限禁止退出您的根文件夹DangerZone:我只需要打开此文件并将其放入图像标记中,Adriano Repetti:是的,我可以打开此文件le,我有权限在此服务器文件夹中放置、读取和删除我的意思是:您对IIS用户有权限吗?您与Windows资源管理器和IIS用户使用的交互使用是不同的(具有不同的权限集).也许这就是问题所在,我必须在哪里更改它?应用程序池内配置?我使用DefaultAppPool我不会将此作为答案发布,因为这更多是一个建议,而且很有可能不是问题所在…但我最近在一个项目中工作,该异常被抛出,因为我试图创建一个子目录来保存文件一个服务器,我有读取权限,但没有写入权限来实际创建它。你可以从Windows资源管理器打开,但它是由其他用户运行的。此外,默认情况下,安全权限禁止从根文件夹中传出DangerZone:我只需要打开此文件并将其放入图像标记中,Adriano Repetti:是的,我可以打开此文件,我知道了ve在此服务器文件夹中放置、读取和删除的权限我的意思是:您对IIS用户有权限吗?您与Windows资源管理器和IIS用户使用的交互使用不同(具有不同的权限集)。可能是问题所在,我必须更改此设置?应用程序池内配置?Im使用DefaultAppPool
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'.