UnauthorizedAccessException Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
İşletim sistemi bir 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
- Devralma
- Türetilmiş
- Öznitelikler
Örnekler
Aşağıdaki örnek, salt okunur bir dosyaya yazmaya çalışırken oluşan özel durumu gösterir 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.
UnauthorizedAccessException
HRESULT
COR_E_UNAUTHORIZEDACCESS0x80070005 değerine sahip olan değerini kullanır.
Oluşturucular
| Name | Description |
|---|---|
| UnauthorizedAccessException() |
UnauthorizedAccessException sınıfının yeni bir örneğini başlatır. |
| UnauthorizedAccessException(SerializationInfo, StreamingContext) |
Geçersiz.
Serileştirilmiş verilerle sınıfının yeni bir örneğini UnauthorizedAccessException başlatır. |
| UnauthorizedAccessException(String, Exception) |
Sınıfın UnauthorizedAccessException yeni bir örneğini belirtilen bir hata iletisiyle ve bu özel durumun nedeni olan iç özel duruma başvuruyla başlatır. |
| UnauthorizedAccessException(String) |
Belirtilen bir hata iletisiyle sınıfının yeni bir örneğini UnauthorizedAccessException başlatır. |
Özellikler
| Name | Description |
|---|---|
| Data |
Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu 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
| Name | Description |
|---|---|
| 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) |
Geçersiz.
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 Objectbasit 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
| Name | Description |
|---|---|
| SerializeObjectState |
Geçersiz.
Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir. (Devralındığı yer: Exception) |