asp.net-mvc 为什么即使在授予 IIS_IUSRS 对目录的写入权限后,我仍然收到“访问路径 'C:\...\...' 被拒绝”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5292148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:59:47  来源:igfitidea点击:

Why am I still getting "Access to the path 'C:\...\...' is denied" even after granting IIS_IUSRS write permission on the directory?

asp.net-mvciis-7permissionsaspose

提问by Ben

I've written a method on my controller that auto generates a powerpoint deck for my client and all that works fine...except I'm stuck on the part about saving the file to disk.

我在我的控制器上写了一个方法,它自动为我的客户生成一个 powerpoint 甲板,一切正常......除了我坚持将文件保存到磁盘的部分。

I'm no stranger to this concept; and "thought" that all I needed to do is grant IIS_IUSRS write permission on the directory and read permission on all parent directories. I'm using IIS 7, and I've done this before with IIS 6 granting NETWORK SERVICE the same permissions.

我对这个概念并不陌生。并且“认为”我需要做的就是授予 IIS_IUSRS 对该目录的写入权限和对所有父目录的读取权限。我正在使用 IIS 7,并且我之前已经使用 IIS 6 授予 NETWORK SERVICE 相同的权限。

Just for kicks, I even gave EVERYONE write permissions on the directory and I still keep getting the Exception: System.UnauthorizedAccessException: Access to the path 'C:......\Content\PPT' is denied. (I removed some of the path for simplicity).

只是为了踢球,我什至给了每个人对该目录的写权限,但我仍然不断收到异常:System.UnauthorizedAccessException:对路径“C:......\Content\PPT”的访问被拒绝。(为简单起见,我删除了一些路径)。

Is there anything else I am overlooking? The server it's on is the first one I've set up, so I just may have overlooked something?

还有什么我忽略的吗?它所在的服务器是我设置的第一个服务器,所以我可能忽略了一些东西?

Here's my controller method simplified:

这是我的控制器方法简化:

public ActionResult CreatePowerPoint()
    {
        string path = HttpContext.Server.MapPath("~/Content/PPT");

        Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation();
        CreatePresentation(presentation);

        presentation.Save(path, Aspose.Slides.Export.SaveFormat.Ppt);

        return View();
    }
}

the presentation.Save() method takes a path and a save format...I don't know what else to try... Is there something wrong with my code? Am I creating the path incorrectly? I can also pass a Stream stream into the save method, but I am not sure if that will fix the problem.

Presentation.Save() 方法采用路径和保存格式...我不知道还能尝试什么...我的代码有问题吗?我是否错误地创建了路径?我还可以将 Stream 流传递到 save 方法中,但我不确定这是否能解决问题。

回答by Ben

I found the solution - I'm using IIS 7, and I had the application pool set to the wrong identity. In IIS 7, I simply changed the identity of the application pool my app is running on and boom, everything worked. I used NETWORK SERVICE as my identity.

我找到了解决方案 - 我使用的是 IIS 7,并且我将应用程序池设置为错误的身份。在 IIS 7 中,我只是更改了我的应用程序运行所在的应用程序池的标识,然后一切正常。我使用网络服务作为我的身份。

Also for those using Aspose Slides, I also had to make sure the file name was in the path.

同样对于那些使用 Aspose Slides 的人,我还必须确保文件名在路径中。

回答by Rudy

The application pool identity has to be set to "Network Service" (as an example of a valid user you can use to run the service). But you also have to set in IIS Admin Authentication\Anonymous Authentication enabled and Anonymous User Identity to "Application pool identity". Without this I was still gettings access denied exceptions on file upload.

应用程序池标识必须设置为“网络服务”(作为可用于运行服务的有效用户的示例)。但是您还必须在 IIS Admin Authentication\Anonymous Authentication enabled 和 Anonymous User Identity 中设置为“应用程序池身份”。如果没有这个,我仍然会在文件上传时遇到访问被拒绝的异常。

回答by Mauricio Morales

I ran into this issue, but it was really because the files were marked as Read-Only in the NTFS FS.

我遇到了这个问题,但这确实是因为文件在 NTFS FS 中被标记为只读。

In my case, it was a new FileStream(path, FileMode.Open)that was failing, and was easily corrected by replacing that with a File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read).

就我而言,它是new FileStream(path, FileMode.Open)失败的,并且可以通过将其替换为File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read).

Bottom line, even if the file is readable, just specifying the FileMode.Openseems to default into FileAccess.ReadWrite.

最重要的是,即使文件可读,只需指定FileMode.Open似乎默认为FileAccess.ReadWrite.

回答by Ro.

I was having same issue, the problem was I did not remove the Read Only checkboxon the properties for the given folder.

我遇到了同样的问题,问题是我没有删除给定文件夹属性上的只读复选框