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

本文关键字:客户端 驱动器 访问 站点 IIS | 更新日期: 2023-09-27 18:13:08

我正在做一个允许用户上传/下载文件到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服务正在使用网络帐户。

任何帮助都是感激的。

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

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

在IIS中,它正在使用一个使用网络服务的池(是的,我也尝试过本地系统,没有运气)。至于网站权限,我只允许读和写。

如果有人可以帮助,甚至更好的是有一个快速的样本项目,我将非常感激。

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

其实我之前已经回答过同样的问题了…

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

这是从那篇文章中复制的步骤。

将文件夹的权限授予应用程序池。你可以在Windows中浏览文件夹并编辑权限,并添加IIS APPPOOL'appPoolNameHere作为用户,然后给它任何你需要的权限。

按部就班的指导…

-打开Windows资源管理器

-浏览到你的文件夹

-右键单击文件夹,选择属性

-在安全选项卡上单击编辑

点击添加

-在Locations下,确保它指向本地机器,而不是域

-对象名称,在下面输入,但用应用程序池的名称替换myappool…

IIS APPPOOL ' MyAppPool

-设置权限为Full,或者只是添加Write,或者任何你需要的