调试模式下的C#和网络上的文件访问 [英] C# in Debug mode and file access on a network

查看:67
本文介绍了调试模式下的C#和网络上的文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我对C#中的Using语句有疑问

使用(FileStream fs = new FileStream(filepath,FileMode.Open,FileAccess.Read,FileShare.ReadWrite))

有时,当我在Windows服务器上浏览将近600万个文档时,会出现拒绝访问"异常

在未将特定网络组添加到文件ACL的情况下,会发生这种情况.为什么这种情况(永远不会如此)发生令人困惑,但我将其保存以供以后调查.

当发生这种情况时,我可以在本地CMD框中使用开发PC上的XCACLS将网络组添加到文件ACL中,没有问题.

我的问题是,在以调试模式运行(VS 2005)时,VS是否以与我的帐户不同的安全原则运行? (是否有此异常?)


环境的配置如下:

文档商店----

Windows Server 2003 64位共享文件夹,DOCS_ADMIN组在共享和文件夹级别具有完整权限

我也是该服务器上Administrators成员的另一个组.

本地PC:

带有VS 2005的Crappy XP

我这样做的原因是,许多用户已将2007 Office文件作为Office 2003文件导入到Doc Management System中,然后发现他们无法读取文件,因为DM应用程序已对扩展名进行了重命名.因此,我必须在文档存储中四处查看文件的签名,以查看它是否实际上是Office 2007文件. (待稍后修复)

如果它在其他安全上下文中运行,则可以在Try/Catch块中围绕它进行编码.

干杯,
DB

Hello all.

I have a question on the Using statement in C# e.g.

using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

Occasionally, as I loop through the near 6 million docs on a Windows server I will get an Access Denied exception

This occurs where a specific network group has not been added to the files ACL. Why this situation, which should never be the case, occurs is perplexing but I''ll save that for later investigation.

When it does occur I can use XCACLS from the development PC, in a local CMD box, to add the network group to the files ACL, no problems.

My question is, while running in debug mode (VS 2005), is VS running in a different Security Principle than my account ? (Hence this exception ?)


The environment is configured like so:

Document store ----

Windows Server 2003 64bit, shared folder where the DOCS_ADMIN group has full rights at share and folder level

I''m also in another group which is a member of the Administrators on this server.

Local PC:

Crappy XP with VS 2005

Why I am doing this is that many users have imported 2007 Office files into the Doc Management System as Office 2003 files - and then finding that they cant read the files, since the DM app kindly renames the extension. So I have to trawl through the document store looking at the file''s signature to see if it''s actually an Office 2007 file. (To be fixed later)

If it is running in a different security context I may be able to code around it in the Try/Catch block.

Cheers,
DB

推荐答案

调试器不应在其他安全上下文中运行.您可以尝试下面的链接来检查访问权限,也可以使用它来检查使用哪个帐户.也可能是服务器(或另一个用户)当前正在对该文件执行某些操作.

您可以尝试检查访问权限,尝试打开并记录所有锁定的文件. (您还可以创建无法访问的文件的集合,然后稍后再尝试).在将此信息记录到日志文件中时,您还可以查看这些异常是否在未处于调试模式时被引发,并且只是被静默丢弃和未被检测到. .

检查文件或文件夹上的用户权限 [
The debugger should not run in another security context. You could try the link below to check the access rights and can also use this to check which account is used for this. It could also be that the server (or another user) is currently performing some operation on the file.

You could try to check the access rights, try to open and log any files locked. (you could also create a collection of files that could not be accessed and try those again later) When you log this information to a log file you can also see if these exceptions where also raised when not in debug mode and simply silently discarded and undetected.

Check User Permissions On A File or Folder[^]

Good luck!


这篇关于调试模式下的C#和网络上的文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆