horizedAccessException与SecurityE

horizedAccessException与SecurityE

本文介绍了UnauthorizedAccessException与SecurityException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileStream的MSDN构造函数表示它可能会抛出UnauthorizedAccessException或SecurityException。以下是MSDN对这些例外的看法。

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.


当操作系统由于I / O错误或特定类型的安全错误而拒绝访问时抛出的异常。

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?

推荐答案

A UnauthorizedAccessException 当访问磁盘上的文件时存在权限错误。这是操作系统级别的错误,例如正常用户试图覆盖操作系统文件(如kernel32.dll)。

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 如果CLR级别存在安全冲突,则抛出SecurityException 。例如,如果您作为低访问ClickOnce应用程序运行,并尝试读取/写入该进程中被CLR安全设置禁止的文件系统中的某个位置。

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.

这篇关于UnauthorizedAccessException与SecurityException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:17