UnauthorizedAccessException 与 SecurityException

发布于 2024-08-22 14:47:31 字数 465 浏览 4 评论 0原文

FileStream 的 MSDN 构造函数表示它可能抛出 UnauthorizedAccessException 或 SecurityException。以下是 MSDN 关于这些异常的说明。

UnauthorizedAccessException: 当操作系统因 I/O 错误或特定类型的安全错误而拒绝访问时引发的异常。

安全异常: 检测到安全错误时引发的异常。

这两个相似的异常有何不同?什么情况会触发其中任何一个?

The MSDN constructor for a FileStream says that it may throw either an UnauthorizedAccessException or a SecurityException. Here's what MSDN says about these exceptions.

UnauthorizedAccessException:
The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.

SecurityException:
The exception that is thrown when a security error is detected.

How are these two similar exceptions different? What situations will trigger either of them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘曦 2024-08-29 14:47:31

当访问磁盘上的文件时出现权限错误时,会引发 UnauthorizedAccessException。这是操作系统级别的错误,例如普通用户尝试覆盖操作系统文件(如 kernel32.dll)。

如果 CLR 级别存在安全违规,则会引发 SecurityException。例如,如果您作为低访问 ClickOnce 应用程序运行,并尝试读取/写入进程中 CLR 安全设置禁止的文件系统中的某个位置。

A UnauthorizedAccessException is thrown when there is a permissions error accessing the file on disk. That is an error at the operating system level such as a normal user trying to overwrite an operating system file (like kernel32.dll).

A SecurityException is thrown if there is a security violation at the CLR level. For example if you are running as a low access ClickOnce application and attempt to read / write to a place in the file system forbidden by the CLR security settings in the process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文