API Management ilke ifadeleri

UYGULANANLAR: Tüm API Management katmanları

Bu makalede, C# 7'de ilke ifadelerinin söz dizimi açıklanmaktadır. Her ifadenin erişimi vardır:

Sözdizimi

  • Tek deyimli ifadeler:
    • içine alınmış @(expression), burada expression iyi biçimlendirilmiş bir C# ifade deyimidir.
  • Çok deyimli ifadeler:
    • içine alınmalıdır @{expression}.
    • Çok deyimli ifadeler içindeki tüm kod yolları bir return deyimle bitmelidir.

Örnekler

@(true)

@((1+1).ToString())

@("Hi There".Length)

@(Regex.Match(context.Response.Headers.GetValueOrDefault("Cache-Control",""), @"max-age=(?<maxAge>\d+)").Groups["maxAge"]?.Value)

@(context.Variables.ContainsKey("maxAge") ? int.Parse((string)context.Variables["maxAge"]) : 3600)

@{
  string[] value;
  if (context.Request.Headers.TryGetValue("Authorization", out value))
  {
      if(value != null && value.Length > 0)
      {
          return Encoding.UTF8.GetString(Convert.FromBase64String(value[0]));
      }
  }
  return null;

}

Kullanım

İlke başvurusu aksini belirtmediği sürece, ifadeler herhangi bir API Management ilkesinde öznitelik değerleri veya metin değerleri olarak kullanılabilir.

Önemli

İlke tanımlandığında, ilke ifadeleri yalnızca sınırlı doğrulamaya sahip olur. İfadeler ağ geçidi tarafından çalışma zamanında yürütülür. İlke ifadeleri tarafından oluşturulan özel durumlar çalışma zamanı hatasıyla sonuçlanır.

İlke ifadelerinde izin verilen .NET Framework türleri

Aşağıdaki tabloda ilke ifadelerinde izin verilen .NET Framework türleri ve üyeleri listelenmektedir.

Tür Desteklenen üyeler
Newtonsoft.Json.Formatting Tümü
Newtonsoft.Json.JsonConvert SerializeObject, DeserializeObject
Newtonsoft.Json.Linq.Extensions Tümü
Newtonsoft.Json.Linq.JArray Tümü
Newtonsoft.Json.Linq.JConstructor Tümü
Newtonsoft.Json.Linq.JContainer Tümü
Newtonsoft.Json.Linq.JObject Tümü
Newtonsoft.Json.Linq.JProperty Tümü
Newtonsoft.Json.Linq.JRaw Tümü
Newtonsoft.Json.Linq.JToken Tümü
Newtonsoft.Json.Linq.JTokenType Tümü
Newtonsoft.Json.Linq.JValue Tümü
System.Array Tümü
System.BitConverter Tümü
System.Boolean Tümü
System.Byte Tümü
System.Char Tümü
System.Collections.Generic.Dictionary<TKey, TValue> Tümü
System.Collections.Generic.HashSet<T> Tümü
System.Collections.Generic.ICollection<T> Tümü
System.Collections.Generic.IDictionary<TKey, TValue> Tümü
System.Collections.Generic.IEnumerable<T> Tümü
System.Collections.Generic.IEnumerator<T> Tümü
System.Collections.Generic.IList<T> Tümü
System.Collections.Generic.IReadOnlyCollection<T> Tümü
System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> Tümü
System.Collections.Generic.ISet<T> Tümü
System.Collections.Generic.KeyValuePair<TKey, TValue> Tümü
System.Collections.Generic.List<T> Tümü
System.Collections.Generic.Queue<T> Tümü
System.Collections.Generic.Stack<T> Tümü
System.Convert Tümü
System.DateTime (Oluşturucu), Add, , , AddHours, AddMilliseconds, AddMinutes, AddMonths, , AddSeconds, AddTicks, DateAddYears, DayDayOfWeek, HourDayOfYearMaxValueDaysInMonthIsLeapYearIsDaylightSavingTimeMillisecondMinute, MinValue, , Month, Now, , Parse, Second, , , TicksUtcNowTimeOfDayToStringTodaySubtractAddDaysYear
System.DateTimeKind Utc
System.DateTimeOffset Tümü
System.Decimal Tümü
System.Double Tümü
System.Enum Parse, TryParse, ToString
System.Exception Tümü
System.Guid Tümü
System.Int16 Tümü
System.Int32 Tümü
System.Int64 Tümü
System.IO.StringReader Tümü
System.IO.StringWriter Tümü
System.Linq.Enumerable Tümü
System.Math Tümü
System.MidpointRounding Tümü
System.Net.IPAddress AddressFamily, Equals, GetAddressBytes, , IsLoopback, Parse, TryParse, ToString
System.Net.WebUtility Tümü
System.Nullable Tümü
System.Random Tümü
System.SByte Tümü
System.Security.Cryptography.AsymmetricAlgorithm Tümü
System.Security.Cryptography.CipherMode Tümü
System.Security.Cryptography.HashAlgorithm Tümü
System.Security.Cryptography.HashAlgorithmName Tümü
System.Security.Cryptography.HMAC Tümü
System.Security.Cryptography.HMACMD5 Tümü
System.Security.Cryptography.HMACSHA1 Tümü
System.Security.Cryptography.HMACSHA256 Tümü
System.Security.Cryptography.HMACSHA384 Tümü
System.Security.Cryptography.HMACSHA512 Tümü
System.Security.Cryptography.KeyedHashAlgorithm Tümü
System.Security.Cryptography.MD5 Tümü
System.Security.Cryptography.Oid Tümü
System.Security.Cryptography.PaddingMode Tümü
System.Security.Cryptography.RNGCryptoServiceProvider Tümü
System.Security.Cryptography.RSA Tümü
System.Security.Cryptography.RSAEncryptionPadding Tümü
System.Security.Cryptography.RSASignaturePadding Tümü
System.Security.Cryptography.SHA1 Tümü
System.Security.Cryptography.SHA1Managed Tümü
System.Security.Cryptography.SHA256 Tümü
System.Security.Cryptography.SHA256Managed Tümü
System.Security.Cryptography.SHA384 Tümü
System.Security.Cryptography.SHA384Managed Tümü
System.Security.Cryptography.SHA512 Tümü
System.Security.Cryptography.SHA512Managed Tümü
System.Security.Cryptography.SymmetricAlgorithm Tümü
System.Security.Cryptography.X509Certificates.PublicKey Tümü
System.Security.Cryptography.X509Certificates.RSACertificateExtensions Tümü
System.Security.Cryptography.X509Certificates.X500DistinguishedName Name
System.Security.Cryptography.X509Certificates.X509Certificate Tümü
System.Security.Cryptography.X509Certificates.X509Certificate2 Tümü
System.Security.Cryptography.X509Certificates.X509ContentType Tümü
System.Security.Cryptography.X509Certificates.X509NameType Tümü
System.Single Tümü
System.String Tümü
System.StringComparer Tümü
System.StringComparison Tümü
System.StringSplitOptions Tümü
System.Text.Encoding Tümü
System.Text.RegularExpressions.Capture Index, Length, Value
System.Text.RegularExpressions.CaptureCollection Count, Item
System.Text.RegularExpressions.Group Captures, Success
System.Text.RegularExpressions.GroupCollection Count, Item
System.Text.RegularExpressions.Match Empty, Groups, Result
System.Text.RegularExpressions.Regex (Oluşturucu), IsMatch, Match, Matches, Replace, , UnescapeSplit
System.Text.RegularExpressions.RegexOptions Tümü
System.Text.StringBuilder Tümü
System.TimeSpan Tümü
System.TimeZone Tümü
System.TimeZoneInfo.AdjustmentRule Tümü
System.TimeZoneInfo.TransitionTime Tümü
System.TimeZoneInfo Tümü
System.Tuple Tümü
System.UInt16 Tümü
System.UInt32 Tümü
System.UInt64 Tümü
System.Uri Tümü
System.UriPartial Tümü
System.Xml.Linq.Extensions Tümü
System.Xml.Linq.XAttribute Tümü
System.Xml.Linq.XCData Tümü
System.Xml.Linq.XComment Tümü
System.Xml.Linq.XContainer Tümü
System.Xml.Linq.XDeclaration Tümü
System.Xml.Linq.XDocument Tümü, Load
System.Xml.Linq.XDocumentType Tümü
System.Xml.Linq.XElement Tümü
System.Xml.Linq.XName Tümü
System.Xml.Linq.XNamespace Tümü
System.Xml.Linq.XNode Tümü
System.Xml.Linq.XNodeDocumentOrderComparer Tümü
System.Xml.Linq.XNodeEqualityComparer Tümü
System.Xml.Linq.XObject Tümü
System.Xml.Linq.XProcessingInstruction Tümü
System.Xml.Linq.XText Tümü
System.Xml.XmlNodeType Tümü

Bağlam değişkeni

context değişkeni her ilke ifadesinde örtük olarak kullanılabilir. Üyeleri:

  • API isteği ve yanıtıyla ve ilgili özelliklerle ilgili bilgiler sağlayın.
  • Hepsi salt okunur.
Bağlam Değişkeni İzin verilen yöntemler, özellikler ve parametre değerleri
context Api: IApi

Deployment

Geçen: TimeSpan - değeri Timestamp ile geçerli saat arasındaki zaman aralığı

GraphQL

LastError

Operation

Request

RequestId: Guid - benzersiz istek tanımlayıcısı

Response

Subscription

Timestamp: DateTime - isteğin alındığı zaman noktası

Tracing: bool - İzlemenin açık mı yoksa kapalı mı olduğunu gösterir

Kullanıcı

Variables: IReadOnlyDictionary<string, object>

void Trace(message: string)
context.Api Id: string

IsCurrentRevision: bool

Name: string

Path: string

Revision: string

ServiceUrl: IUrl

Version: string

Workspace: IWorkspace
context.Deployment Gateway

GatewayId: string (yönetilen ağ geçitleri için 'yönetilen' döndürür)

Region: string

ServiceId: string

ServiceName: string

Certificates: IReadOnlyDictionary<string, X509Certificate2>
context.Deployment.Gateway Id: string (yönetilen ağ geçitleri için 'yönetilen' döndürür)

InstanceId: string (yönetilen ağ geçitleri için 'yönetilen' döndürür)

IsManaged: bool
context.GraphQL GraphQLArguments: IGraphQLDataObject

Parent: IGraphQLDataObject

Örnekler
context.LastError Source: string

Reason: string

Message: string

Scope: string

Section: string

Path: string

PolicyId: string

hakkında context.LastErrordaha fazla bilgi için bkz . Hata işleme.
context.Operation Id: string

Method: string

Name: string

UrlTemplate: string
context.Product ApprovalRequired: bool

Groups: IEnumerable<IGroup>

Id: string

Name: string

State: enum ProductState {NotPublished, Published}

SubscriptionsLimit: int?

SubscriptionRequired: bool

Workspace: IWorkspace
context.Request Body: IMessageBody veya null isteğin gövdesi yoksa.

Certificate: System.Security.Cryptography.X509Certificates.X509Certificate2

Headers: IReadOnlyDictionary<string, string[]>

IpAddress: string

MatchedParameters: IReadOnlyDictionary<string, string>

Method: string

OriginalUrl: IUrl

Url: IUrl

PrivateEndpointConnection: IPrivateEndpointConnection veya null istek özel uç nokta bağlantısından gelmiyorsa.
string context.Request.Headers.GetValueOrDefault(headerName: string, defaultValue: string) headerName: string

defaultValue: string

Virgülle ayrılmış istek üst bilgisi değerlerini veya defaultValue üst bilgi bulunamazsa döndürür.
context.Response Body: IMessageBody

Headers: IReadOnlyDictionary<string, string[]>

StatusCode: int

StatusReason: string
string context.Response.Headers.GetValueOrDefault(headerName: string, defaultValue: string) headerName: string

defaultValue: string

Virgülle ayrılmış yanıt üst bilgisi değerlerini veya defaultValue üst bilgi bulunamazsa döndürür.
context.Subscription CreatedDate: DateTime

EndDate: DateTime?

Id: string

Key: string

Name: string

PrimaryKey: string

SecondaryKey: string

StartDate: DateTime?
context.User Email: string

FirstName: string

Groups: IEnumerable<IGroup>

Id: string

Identities: IEnumerable<IUserIdentity>

LastName: string

Note: string

RegistrationDate: DateTime
IApi Id: string

Name: string

Path: string

Protocols: IEnumerable<string>

ServiceUrl: IUrl

SubscriptionKeyParameterNames: ISubscriptionKeyParameterNames
IGraphQLDataObject Henüz belirlenmedi

IGroup Id: string

Name: string
IMessageBody As<T>(bool preserveContent = false): Where T: string, byte[], JObject, JToken, JArray, XNode, XElement, XDocument

context.Request.Body.As<T>- ve context.Response.Body.As<T> yöntemleri, belirtilen türde Tbir istek veya yanıt iletisi gövdesini okur.

-Veya-

AsFormUrlEncodedContent(bool preserveContent = false)

context.Request.Body.AsFormUrlEncodedContent()- ve context.Response.Body.AsFormUrlEncodedContent() yöntemleri, istek veya yanıt iletisi gövdesinde URL ile kodlanmış form verilerini okur ve bir IDictionary<string, IList<string> nesne döndürür. Kodu çözülen nesne işlemleri ve şu ifadeleri destekler IDictionary : ToQueryString(), JsonConvert.SerializeObject(), ToFormUrlEncodedContent().

Varsayılan olarak As<T> ve AsFormUrlEncodedContent() yöntemleri:
  • Özgün ileti gövdesi akışını kullanın.
  • Döndürdüğünde kullanılamaz duruma getirir.

Bunu önlemek ve yönteminin gövde akışının bir kopyası üzerinde çalışması için, set-body ilkesinin preserveContent örneklerinde gösterildiği gibi parametresini trueolarak ayarlayın.
IPrivateEndpointConnection Name: string

GroupId: string

MemberName: string

Daha fazla bilgi için bkz . REST API.
IUrl Host: string

Path: string

Port: int

Query: IReadOnlyDictionary<string, string[]>

QueryString: string

Scheme: string
ISubscriptionKeyParameterNames Header: string

Query: string
string IUrl.Query.GetValueOrDefault(queryParameterName: string, defaultValue: string) queryParameterName: string

defaultValue: string

Virgülle ayrılmış sorgu parametresi değerlerini veya defaultValue parametre bulunamazsa döndürür.
IUserIdentity Id: string

Provider: string
IWorkspace Id: string

Name: string
T context.Variables.GetValueOrDefault<T>(variableName: string, defaultValue: T) variableName: string

defaultValue: T

Türüne TdefaultValue veya değişkeni bulunamazsa değişken değeri türe dönüştürmeyi döndürür.

Belirtilen tür döndürülen değişkenin gerçek türüyle eşleşmiyorsa bu yöntem bir özel durum oluşturur.
BasicAuthCredentials AsBasic(input: this string) input: string

Giriş parametresi geçerli bir HTTP Temel Kimlik Doğrulaması yetkilendirme isteği üst bilgi değeri içeriyorsa, yöntem türünde BasicAuthCredentialsbir nesne döndürür; aksi takdirde yöntem null döndürür.
bool TryParseBasic(input: this string, result: out BasicAuthCredentials) input: string

result: out BasicAuthCredentials

Giriş parametresi istek üst bilgisinde geçerli bir HTTP Temel Kimlik Doğrulaması yetkilendirme değeri içeriyorsa, yöntem döndürür true ve sonuç parametresi türünde BasicAuthCredentialsbir değer içerir; aksi takdirde yöntemi döndürür false.
BasicAuthCredentials Password: string

UserId: string
Jwt AsJwt(input: this string) input: string

Giriş parametresi geçerli bir JWT belirteci değeri içeriyorsa, yöntemi türünde Jwtbir nesnesi döndürür; aksi takdirde yöntemi döndürür null.
bool TryParseJwt(input: this string, result: out Jwt) input: string

result: out Jwt

Giriş parametresi geçerli bir JWT belirteci değeri içeriyorsa, yöntemi döndürür true ve sonuç parametresi türünde Jwtbir değer içerir; aksi takdirde yöntemi döndürür false.
Jwt Algorithm: string

Audiences: IEnumerable<string>

Claims: IReadOnlyDictionary<string, string[]>

ExpirationTime: DateTime?

Id: string

Issuer: string

IssuedAt: DateTime?

NotBefore: DateTime?

Subject: string

Type: string
string Jwt.Claims.GetValueOrDefault(claimName: string, defaultValue: string) claimName: string

defaultValue: string

Virgülle ayrılmış talep değerlerini veya defaultValue üst bilgi bulunamazsa döndürür.
byte[] Encrypt(input: this byte[], alg: string, key:byte[], iv:byte[]) input - şifrelenecek düz metin

alg - simetrik şifreleme algoritmasının adı

key - şifreleme anahtarı

iv - başlatma vektöru

Şifrelenmiş düz metin döndürür.
byte[] Encrypt(input: this byte[], alg: System.Security.Cryptography.SymmetricAlgorithm) input - şifrelenecek düz metin

alg - şifreleme algoritması

Şifrelenmiş düz metin döndürür.
byte[] Encrypt(input: this byte[], alg: System.Security.Cryptography.SymmetricAlgorithm, key:byte[], iv:byte[]) input - şifrelenecek düz metin

alg - şifreleme algoritması

key - şifreleme anahtarı

iv - başlatma vektöru

Şifrelenmiş düz metin döndürür.
byte[] Decrypt(input: this byte[], alg: string, key:byte[], iv:byte[]) input - Şifresi çözülecek şifre metni

alg - simetrik şifreleme algoritmasının adı

key - şifreleme anahtarı

iv - başlatma vektöru

Düz metin döndürür.
byte[] Decrypt(input: this byte[], alg: System.Security.Cryptography.SymmetricAlgorithm) input - Şifresi çözülecek şifre metni

alg - şifreleme algoritması

Düz metin döndürür.
byte[] Decrypt(input: this byte[], alg: System.Security.Cryptography.SymmetricAlgorithm, key:byte[], iv:byte[]) input - Şifresi çözülecek şifre metni

alg - şifreleme algoritması

key - şifreleme anahtarı

iv - başlatma vektöru

Düz metin döndürür.
bool VerifyNoRevocation(input: this System.Security.Cryptography.X509Certificates.X509Certificate2) Sertifika iptal durumunu denetlemeden X.509 zincir doğrulaması gerçekleştirir.

input - sertifika nesnesi

Doğrulama başarılı olursa, false doğrulama başarısız olursa döndürürtrue.

İlkelerle çalışma hakkında daha fazla bilgi için bkz:

Daha fazla bilgi için: