UnauthorizedAccessException Sınıf

Tanım

İşletim sistemi G/Ç hatası veya belirli bir güvenlik hatası türü nedeniyle erişimi reddettiyse oluşan özel durum.

public ref class UnauthorizedAccessException : Exception
public ref class UnauthorizedAccessException : SystemException
public class UnauthorizedAccessException : Exception
public class UnauthorizedAccessException : SystemException
[System.Serializable]
public class UnauthorizedAccessException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class UnauthorizedAccessException : SystemException
type UnauthorizedAccessException = class
    inherit Exception
type UnauthorizedAccessException = class
    inherit SystemException
[<System.Serializable>]
type UnauthorizedAccessException = class
    inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type UnauthorizedAccessException = class
    inherit SystemException
Public Class UnauthorizedAccessException
Inherits Exception
Public Class UnauthorizedAccessException
Inherits SystemException
Devralma
UnauthorizedAccessException
Devralma
UnauthorizedAccessException
Türetilmiş
Öznitelikler

Örnekler

Aşağıdaki örnekte, salt okunur bir dosyaya yazmaya çalışılırken oluşan özel durum gösterilmektedir UnauthorizedAccessException .

using System;
using System.IO;

public class Example
{
   public static void Main()
   {
      string filePath = @".\ROFile.txt";
      if (! File.Exists(filePath))
         File.Create(filePath);
      // Keep existing attributes, and set ReadOnly attribute.
      File.SetAttributes(filePath, 
                        (new FileInfo(filePath)).Attributes | FileAttributes.ReadOnly);

      StreamWriter sw = null;
      try {
         sw = new StreamWriter(filePath);
         sw.Write("Test");
      }
      catch (UnauthorizedAccessException) {
         FileAttributes attr = (new FileInfo(filePath)).Attributes;
         Console.Write("UnAuthorizedAccessException: Unable to access file. ");
         if ((attr & FileAttributes.ReadOnly) > 0)
            Console.Write("The file is read-only."); 
       }
       finally {
         if (sw != null) sw.Close();
      }   
   }
}
// The example displays the following output:
//    UnAuthorizedAccessException: Unable to access file. The file is read-only.
open System
open System.IO


let filePath = @".\ROFile.txt"
if File.Exists filePath |> not then
    File.Create filePath |> ignore
// Keep existing attributes, and set ReadOnly attribute.
File.SetAttributes(filePath, (FileInfo filePath).Attributes ||| FileAttributes.ReadOnly)

do
    use sw = new StreamWriter(filePath)
    try
        sw.Write "Test"
    with :? UnauthorizedAccessException ->
        let attr = (FileInfo filePath).Attributes
        printf "UnAuthorizedAccessException: Unable to access file. "
        if int (attr &&& FileAttributes.ReadOnly) > 0 then
            printf "The file is read-only."
// The example displays the following output:
//    UnAuthorizedAccessException: Unable to access file. The file is read-only.
Imports System.IO

Module Example
   Public Sub Main()
      Dim filePath As String = ".\ROFile.txt"
      If Not File.Exists(filePath) Then File.Create(filePath)
      ' Keep existing attributes, and set ReadOnly attribute.
      File.SetAttributes(filePath, 
                        (New FileInfo(filePath)).Attributes Or FileAttributes.ReadOnly)

      Dim sw As StreamWriter = Nothing
      Try
         sw = New StreamWriter(filePath)
         sw.Write("Test")
      Catch e As UnauthorizedAccessException
         Dim attr As FileAttributes = (New FileInfo(filePath)).Attributes
         Console.Write("UnAuthorizedAccessException: Unable to access file. ")
         If (attr And FileAttributes.ReadOnly) > 0 Then
            Console.Write("The file is read-only.") 
         End If
       Finally
         If sw IsNot Nothing Then sw.Close()
      End Try   
   End Sub
End Module
' The example displays the following output:
'   UnAuthorizedAccessException: Unable to access file. The file is read-only.

Açıklamalar

Genellikle UnauthorizedAccessException bir Windows API çağrısını sarmalayan bir yöntem tarafından özel durum oluşturulur. Özel durumun nedenlerini bulmak için özel durum nesnesinin Message özelliğinin metnini inceleyin.

UnauthorizedAccessExceptionHRESULT COR_E_UNAUTHORIZEDACCESSdeğeri 0x80070005 olan öğesini kullanır.

Oluşturucular

UnauthorizedAccessException()

UnauthorizedAccessException sınıfının yeni bir örneğini başlatır.

UnauthorizedAccessException(SerializationInfo, StreamingContext)

UnauthorizedAccessException sınıfının yeni bir örneğini serileştirilmiş verilerle başlatır.

UnauthorizedAccessException(String)

Belirtilen hata iletisiyle sınıfının yeni bir örneğini UnauthorizedAccessException başlatır.

UnauthorizedAccessException(String, Exception)

Belirtilen bir hata iletisi ve bu özel durumun nedeni olan iç özel duruma başvuru ile sınıfının yeni bir örneğini UnauthorizedAccessException başlatır.

Özellikler

Data

Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan bir anahtar/değer çifti koleksiyonu alır.

(Devralındığı yer: Exception)
HelpLink

Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar.

(Devralındığı yer: Exception)
HResult

Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar.

(Devralındığı yer: Exception)
InnerException

Exception Geçerli özel duruma neden olan örneği alır.

(Devralındığı yer: Exception)
Message

Geçerli özel durumu açıklayan bir ileti alır.

(Devralındığı yer: Exception)
Source

Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar.

(Devralındığı yer: Exception)
StackTrace

Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır.

(Devralındığı yer: Exception)
TargetSite

Geçerli özel durumu oluşturan yöntemini alır.

(Devralındığı yer: Exception)

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetBaseException()

Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan değerini döndürür Exception .

(Devralındığı yer: Exception)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetObjectData(SerializationInfo, StreamingContext)

Türetilmiş bir sınıfta geçersiz kılındığında, özel durum hakkındaki bilgilerle öğesini ayarlar SerializationInfo .

(Devralındığı yer: Exception)
GetType()

Geçerli örneğin çalışma zamanı türünü alır.

(Devralındığı yer: Exception)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli özel durumun dize gösterimini oluşturur ve döndürür.

(Devralındığı yer: Exception)

Ekinlikler

SerializeObjectState
Kullanımdan kalktı.

Bir özel durum, özel durum hakkında serileştirilmiş veriler içeren bir özel durum nesnesi oluşturmak üzere seri hale getirildiğinde gerçekleşir.

(Devralındığı yer: Exception)

Şunlara uygulanır

Ayrıca bkz.