SecurityCallContext 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.
Geçerli yöntem çağrısına giden çağıran zincirini açıklar.
public ref class SecurityCallContext sealed
public sealed class SecurityCallContext
type SecurityCallContext = class
Public NotInheritable Class SecurityCallContext
- Devralma
-
SecurityCallContext
Örnekler
Aşağıdaki kod örneği, bir sınıfın SecurityCallContext yöntemlerine ServicedComponent yapılan çağrıların güvenlik bağlamını sorgulamak için sınıfının kullanımını gösterir.
// Accept a constructor string.
[ConstructionEnabled]
public ref class EmployeeInformation: public ServicedComponent
{
private:
// The employee's user name and salary.
String^ accountName;
double salary;
public:
// Get the employee's name. All users can call this method.
String^ GetName()
{
return (accountName);
}
// Set the employee's salary. Only managers can do this.
void SetSalary( double ammount )
{
if ( SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
{
salary = ammount;
}
else
{
throw gcnew UnauthorizedAccessException;
}
}
// Get the employee's salary. Only the employee and managers can do this.
double GetSalary()
{
if ( SecurityCallContext::CurrentCall->DirectCaller->AccountName == accountName || SecurityCallContext::CurrentCall->IsCallerInRole( "Manager" ) )
{
return (salary);
}
else
{
throw gcnew UnauthorizedAccessException;
}
}
protected:
// Use the constructor string.
// This method is called when the object is instantiated.
virtual void Construct( String^ constructorString ) override
{
accountName = constructorString;
}
};
// Accept a constructor string.
[ConstructionEnabled]
public class EmployeeInformation : ServicedComponent
{
// The employee's user name and salary.
private string accountName;
private double salary = 0;
// Get the employee's name. All users can call this method.
public string GetName ()
{
return(accountName);
}
// Set the employee's salary. Only managers can do this.
public void SetSalary (double ammount)
{
if (SecurityCallContext.CurrentCall.IsCallerInRole("Manager"))
{
salary = ammount;
}
else
{
throw new UnauthorizedAccessException();
}
}
// Get the employee's salary. Only the employee and managers can do this.
public double GetSalary ()
{
if ( SecurityCallContext.CurrentCall.DirectCaller.AccountName == accountName ||
SecurityCallContext.CurrentCall.IsCallerInRole("Manager") )
{
return(salary);
}
else
{
throw new UnauthorizedAccessException();
}
}
// Use the constructor string.
// This method is called when the object is instantiated.
protected override void Construct (string constructorString)
{
accountName = constructorString;
}
}
' Accept a constructor string.
<ConstructionEnabled()> _
Public Class EmployeeInformation
Inherits ServicedComponent
' The employee's user name and salary.
Private accountName As String
Private salary As Double = 0
' Get the employee's name. All users can call this method.
Public Function GetName() As String
Return accountName
End Function 'GetName
' Set the employee's salary. Only managers can do this.
Public Sub SetSalary(ByVal ammount As Double)
If SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
salary = ammount
Else
Throw New UnauthorizedAccessException()
End If
End Sub
' Get the employee's salary. Only the employee and managers can do this.
Public Function GetSalary() As Double
If SecurityCallContext.CurrentCall.DirectCaller.AccountName = accountName OrElse SecurityCallContext.CurrentCall.IsCallerInRole("Manager") Then
Return salary
Else
Throw New UnauthorizedAccessException()
End If
End Function 'GetSalary
' Use the constructor string.
' This method is called when the object is instantiated.
Protected Overrides Sub Construct(ByVal constructorString As String)
accountName = constructorString
End Sub
End Class
Özellikler
Callers |
Çağıranı tanımlayan bir SecurityCallers nesnesi alır. |
CurrentCall |
Güvenlik çağrısı bağlamını açıklayan bir SecurityCallContext nesnesi alır. |
DirectCaller |
Bu yöntemin doğrudan çağıranı açıklayan bir SecurityIdentity nesnesi alır. |
IsSecurityEnabled |
Güvenlik denetimlerinin geçerli bağlamda etkinleştirilip etkinleştirilmediğini belirler. |
MinAuthenticationLevel |
|
NumCallers |
|
OriginalCaller |
Özgün çağıranı tanımlayan bir SecurityIdentity alır. |
Yöntemler
Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
GetType() |
Type Geçerli örneğini alır. (Devralındığı yer: Object) |
IsCallerInRole(String) |
Doğrudan çağıranın belirtilen rolün üyesi olduğunu doğrular. |
IsUserInRole(String, String) |
Belirtilen kullanıcının belirtilen rolde olduğunu doğrular. |
MemberwiseClone() |
Geçerli Objectöğesinin sığ bir kopyasını oluşturur. (Devralındığı yer: Object) |
ToString() |
Geçerli nesneyi temsil eden dizeyi döndürür. (Devralındığı yer: Object) |
Şunlara uygulanır
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin