แก้ไข

แชร์ผ่าน


IdnMapping.UseStd3AsciiRules Property

Definition

Gets or sets a value that indicates whether standard or relaxed naming conventions are used in operations performed by members of the current IdnMapping object.

public:
 property bool UseStd3AsciiRules { bool get(); void set(bool value); };
public bool UseStd3AsciiRules { get; set; }
member this.UseStd3AsciiRules : bool with get, set
Public Property UseStd3AsciiRules As Boolean

Property Value

true if standard naming conventions are used in operations; otherwise, false.

Examples

The following example generates URLs that contain characters in the ASCII range from U+0000 to U+007F and passes them to the GetAscii(String) method of two IdnMapping objects. One object has its UseStd3AsciiRules property set to true, and the other object has it set to false. The output displays the characters that are invalid when the UseStd3AsciiRules property is true but valid when it is false.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      int nFailed = 0;
      IdnMapping idnStd = new IdnMapping();
      idnStd.UseStd3AsciiRules = true;

      IdnMapping idnRelaxed = new IdnMapping();
      idnRelaxed.UseStd3AsciiRules = false;  // The default, but make it explicit.

      for (int ctr = 0; ctr <= 0x7F; ctr++) {
         string name = $"Prose{ctr}ware.com";

         bool stdFailed = false;
         bool relaxedFailed = false;
         string punyCode = "";
         try {
            punyCode = idnStd.GetAscii(name);
         }
         catch (ArgumentException) {
            stdFailed = true;
         }

         try {
            punyCode = idnRelaxed.GetAscii(name);
         }
         catch (ArgumentException) {
            relaxedFailed = true;
         }

         if (relaxedFailed != stdFailed) {
            Console.Write("U+{0:X4}     ", ctr);
            nFailed++;
            if (nFailed % 5 == 0)
               Console.WriteLine();
         }
      }
   }
}
// The example displays the following output:
//       U+0020     U+0021     U+0022     U+0023     U+0024
//       U+0025     U+0026     U+0027     U+0028     U+0029
//       U+002A     U+002B     U+002C     U+002F     U+003A
//       U+003B     U+003C     U+003D     U+003E     U+003F
//       U+0040     U+005B     U+005C     U+005D     U+005E
//       U+005F     U+0060     U+007B     U+007C     U+007D
//       U+007E
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim nFailed As Integer = 0
      Dim idnStd As New IdnMapping()
      idnStd.UseStd3AsciiRules = True
      
      Dim idnRelaxed As New IdnMapping
      idnRelaxed.UseStd3AsciiRules = False     ' The default, but make it explicit.
      
      For ctr As Integer = 0 To &h7F 
         Dim name As String = "Prose" + ChrW(ctr) + "ware.com"
         
         Dim stdFailed As Boolean = False
         Dim relaxedFailed As Boolean = False
         Dim punyCode As String
         Try
            punyCode = idnStd.GetAscii(name)
         Catch e As ArgumentException
            stdFailed = True
         End Try       
         
         Try
            punyCode = idnRelaxed.GetAscii(name)
         Catch e As ArgumentException
            relaxedFailed = True
         End Try       
         
         If relaxedFailed <> stdFailed Then
            Console.Write("U+{0:X4}     ", ctr)
            nFailed += 1
            If nFailed Mod 5 = 0 Then Console.WriteLine()         
         End If 
      Next   
   End Sub
End Module
' The example displays the following output:
'       U+0020     U+0021     U+0022     U+0023     U+0024
'       U+0025     U+0026     U+0027     U+0028     U+0029
'       U+002A     U+002B     U+002C     U+002F     U+003A
'       U+003B     U+003C     U+003D     U+003E     U+003F
'       U+0040     U+005B     U+005C     U+005D     U+005E
'       U+005F     U+0060     U+007B     U+007C     U+007D
'       U+007E

Remarks

Domain names that follow standard naming rules consist of a specific subset of characters in the US-ASCII character range. The characters are the letters A through Z, the digits 0 through 9, the hyphen (-) character (U+002D), and the period (.) character. The case of the characters is not significant. Relaxed naming conventions allow the use of a broader range of ASCII characters, including the space character (U+0020), the exclamation point character (U+0021), and the underbar character (U+005F). If UseStd3AsciiRules is true, only standard characters can appear in a label returned by the GetAscii method.

By default, the value of the UseStd3AsciiRules property is false, and an expanded subset of ASCII characters is permitted in a label.

Note

The IdnMapping class prohibits the use of the nondisplayable characters U+0000 through U+001F, and U+007F in domain name labels regardless of the setting of the UseStd3AsciiRules property. This prohibition reduces the risk of security attacks such as name spoofing.

Applies to