繁体   English   中英

IIS站点无法访问本地客户端驱动器

[英]IIS site cannot access local client drive

我正在做一个项目,允许用户将文件上传/下载到SQL流。

这在本地测试时效果很好,但是当我上载它并具有IIS时,它似乎无法正常工作。 我认为这是一个权限问题。

我无法解决。

我什至尝试使用未投影的文件夹,如下所示(没有运气):

string tempPath = System.IO.Path.GetTempPath();
string tempPath2 = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath3 = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
var fullpath = Path.Combine(tempPath2, "MeDoc.Doc");

我什至尝试使用身份验证,如下所示(也没有运气):

DirectoryInfo di = new DirectoryInfo(fullpath);
DirectorySecurity acl = di.GetAccessControl();
AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(NTAccount));
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(currentUser);

DirectorySecurity fsecurity = Directory.GetAccessControl("C:\\Temp\\Docs\\");
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
FileSystemAccessRule writerule = new FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow);

fsecurity.AddAccessRule(writerule);
// Set the ACL back to the file
Directory.SetAccessControl("C:\\Windows\\Temp\\", fsecurity);

if (!string.IsNullOrEmpty("C:\\Temp\\Docs\\") && Directory.Exists("C:\\Temp\\Docs\\"))
{
    // Get your file's ACL
    DirectorySecurity fsecurity3 = Directory.GetAccessControl("C:\\Temp\\Docs\\");

    // Add the new rule to the ACL`enter code here`
    fsecurity3.AddAccessRule(writerule);

    // Set the ACL back to the file
    Directory.SetAccessControl("C:\\Temp\\Docs\\", fsecurity);
}

即使在web.config中:

<authorization>
<allow users="?"/>
<!--<anonymousAuthentication enabled="true" />-->
</authorization>

IIS服务正在使用网络帐户。

任何帮助表示赞赏。

请注意,在机器上调试时,我使用的几乎所有方法都能完美工作。

当它在运行网络帐户的Web服务器上的IIS上时,情况就不同了。

在IIS中,它使用的池使用网络服务(是的,我也尝试了运气不好的本地系统)。 至于网站许可,我允许读写。

如果有人可以提供帮助,甚至可以做一个更好的示例项目,我将不胜感激。

实际上,我之前已经回答过同样的问题...

https://stackoverflow.com/a/16948507/1246574

这是从该帖子复制的步骤。

将文件夹的权限授予应用程序池。 您将浏览到Windows中的文件夹并编辑权限,并以用户身份添加IIS APPPOOL \\ appPoolNameHere,然后为其提供所需的任何权限。

分步说明...

-打开Windows资源管理器

-浏览到您的文件夹

-右键单击该文件夹,然后转到“属性”

-在“安全性”选项卡上,单击“编辑”

-点击添加

-在“位置”下,确保它指向您的本地计算机,而不是域

-对于对象名称,在下面输入,但将MyAppPool替换为应用程序池的名称...

IIS APPPOOL \\ MyAppPool

-将权限设置为“完全”,或仅添加“写”或任何您需要的权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM