简体   繁体   English

通过asp.net站点执行File.Exists时出现权限问题

[英]Issue with permissions when executing a File.Exists through asp.net site

I've got a script that checks if a file exists. 我有一个脚本来检查文件是否存在。 The path is a network share that exists on the server.. 该路径是服务器上存在的网络共享。

Ie the directory is D:\\Mainfolder\\Subfolder\\file.txt the network share is \\Server\\Subfolder\\file.txt 即目录是D:\\ Mainfolder \\ Subfolder \\ file.txt网络共享是\\ Server \\ Subfolder \\ file.txt

The file exists, however from my asp.net site, it says that it doesn't.. I assume that this is a permissions issue since it works if the file is in a different folder. 该文件存在,但是从我的asp.net站点,它说它没有..我认为这是一个权限问题,因为它可以工作,如果该文件在不同的文件夹中。

I've added a bunch of accounts to the permissions of both the share and the folder, but nothing is working.. 我已经为共享和文件夹的权限添加了一堆帐户,但没有任何工作..

Is there a way to display which user the File.Exists is being executed as? 有没有办法显示正在执行File.Exists的用户?

Thanks 谢谢

The user that is accessing the files is the user configured on the application pool of the ASP.NET site or virtual directory. 正在访问文件的用户是在ASP.NET站点或虚拟目录的应用程序池上配置的用户。 By default, this user will not have access to many local folders/files, let a lone a network share. 默认情况下,此用户无权访问许多本地文件夹/文件,只需一个网络共享。 You have two options: 您有两种选择:

  1. Change the user configured for the application pool to a user that has access to not only the local files necessary to run the site, but also has access to the network share. 将为应用程序池配置的用户更改为不仅可以访问运行站点所需的本地文件,而且还可以访问网络共享的用户。

  2. Configure impersonation in the Web.config. 在Web.config中配置模拟。 See this other SO question here which has a snippet of configuration from Web.config for impersonation. 请参阅此处的另一个问题,其中有一个来自Web.config的配置片段用于模拟。

Some links: 一些链接:

Starting with Vista a Windows Service is not allowed to access "Desktop things" - one of these being a mounted drive letter aka network share... 从Vista开始,Windows服务不允许访问“桌面内容” - 其中一个是已安装的驱动器号,即网络共享...

You could mess around with the permissions etc. but even if you get it to work this is not supported... 你可以搞乱权限等,但即使你让它工作,这是不支持的...

What is the exact goal ? 目标是什么? Perhaps there is some other way... 也许还有其他方式......

It's probably going to be the user that your application pool is running under. 它可能是您的应用程序池正在运行的用户。 You can see the list of application pools in IIS manager. 您可以在IIS管理器中查看应用程序池列表。

However, you can also use Process Monitor to see what users are trying to access the files on your server (including attempts that fail due to insufficient permissions). 但是,您还可以使用Process Monitor查看用户尝试访问服务器上的文件的内容(包括由于权限不足而导致失败的尝试)。 You can find it at http://technet.microsoft.com/en-us/sysinternals/bb896645 . 您可以在http://technet.microsoft.com/en-us/sysinternals/bb896645找到它。 You'll probably need to run this on the remote server where the file actually exists. 您可能需要在文件实际存在的远程服务器上运行它。

Another thing to consider is that while the D:\\ drive might be mapped as a network drive when you log in interactively with your account, it probably doesn't exist when the website user is 'logged in'. 另一件需要考虑的事情是,当您以交互方式登录帐户时,D:\\驱动器可能会映射为网络驱动器,但当网站用户“登录”时,它可能不存在。 You'd be better off telling the website to use the UNC path (\\server\\subfolder...) rather than the D:\\ path. 你最好告诉网站使用UNC路径(\\ server \\ subfolder ...)而不是D:\\路径。

As others have mentioned, your application is probably running under the Application Pool identity. 正如其他人所提到的,您的应用程序可能正在应用程序池标识下运行。 Unless you've changed it explicitly, this account will not show up in your list of accounts to configure. 除非您明确更改了此帐户,否则此帐户不会显示在您要配置的帐户列表中。

Getting that sorted out isn't going to help you, though, if you are attempting to access a resource though a mapped drive, as the mapped drive exists only within the scope of the logged-in user. 但是,如果您尝试通过映射驱动器访问资源,那么整理出来并不会对您有所帮助,因为映射驱动器仅存在于已登录用户的范围内。

Think of it this way: you and a colleague share a machine, and you map drive D:\\ to \\serverA\\Shared\\Matt, your colleague isn't going to log in and have drive D:\\ mapped to your share. 可以这样想:您和同事共享一台机器,并将驱动器D:\\映射到\\ serverA \\ Shared \\ Matt,您的同事不会登录并将驱动器D:\\映射到您的共享。 She can freely map drive D:\\ to \\serverX\\Secret\\Resources. 她可以自由地将驱动器D:\\映射到\\ serverX \\ Secret \\ Resources。

Start by making sure that you are using a UNC path, then work through the web of permissions issues. 首先确保您使用的是UNC路径,然后完成权限网络问题。

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

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