简体   繁体   English

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

[英]IIS site cannot access local client drive

I am doing a project where the user is allowed to upload/download a file to SQL stream. 我正在做一个项目,允许用户将文件上传/下载到SQL流。

This works perfectly when testing it locally but when i uploads it and have an IIS, it seems to not work. 这在本地测试时效果很好,但是当我上载它并具有IIS时,它似乎无法正常工作。 I assumed it is a permission issue. 我认为这是一个权限问题。

I am unable to solve it. 我无法解决。

I even tried to use unprojected folders as shown below (with no luck): 我什至尝试使用未投影的文件夹,如下所示(没有运气):

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");

I even tried using authentications as show below (also no luck): 我什至尝试使用身份验证,如下所示(也没有运气):

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);
}

Even in web.config: 即使在web.config中:

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

the IIS service is using network account. IIS服务正在使用网络帐户。

Any help is appreciated. 任何帮助表示赞赏。

Please note almost all the methods I use work perfectly when debugging on my machine. 请注意,在机器上调试时,我使用的几乎所有方法都能完美工作。

It's a different story when it is on IIS on a web server running network account. 当它在运行网络帐户的Web服务器上的IIS上时,情况就不同了。

In IIS it is using a pool that uses Network service (yes I also tried local system with no luck). 在IIS中,它使用的池使用网络服务(是的,我也尝试了运气不好的本地系统)。 As for the site permission I allow read and write. 至于网站许可,我允许读写。

If anyone can help or even better yet have a quick sample project, I would greatly appreciate it. 如果有人可以提供帮助,甚至可以做一个更好的示例项目,我将不胜感激。

I've actually answered this same question before... 实际上,我之前已经回答过同样的问题...

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

Here's the steps copied from that post. 这是从该帖子复制的步骤。

Grant permissions for your folder to the application pool. 将文件夹的权限授予应用程序池。 You'd browse to the folder in Windows and edit permissions, and add IIS APPPOOL\\appPoolNameHere as a user, then give it whatever permissions you need. 您将浏览到Windows中的文件夹并编辑权限,并以用户身份添加IIS APPPOOL \\ appPoolNameHere,然后为其提供所需的任何权限。

Step by Step Instructions... 分步说明...

-Open Windows Explorer -打开Windows资源管理器

-Browse to your folder -浏览到您的文件夹

-Right click the folder and go to Properties -右键单击该文件夹,然后转到“属性”

-On the Security tab click Edit -在“安全性”选项卡上,单击“编辑”

-Click Add -点击添加

-Under Locations, make sure it is pointing at your local machine, not a domain -在“位置”下,确保它指向您的本地计算机,而不是域

-For the object name, enter below but replace MyAppPool with the name of your application pool... -对于对象名称,在下面输入,但将MyAppPool替换为应用程序池的名称...

IIS APPPOOL\\MyAppPool IIS APPPOOL \\ MyAppPool

-Set the permissions to Full, or just add Write, or whatever you need. -将权限设置为“完全”,或仅添加“写”或任何您需要的权限。

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

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