Uri.IsWellFormedUriString(String, UriKind) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示字串是否正構,嘗試用該字串構造 URI,並確保字串不需要進一步轉義。
public:
static bool IsWellFormedUriString(System::String ^ uriString, UriKind uriKind);
public static bool IsWellFormedUriString(string uriString, UriKind uriKind);
public static bool IsWellFormedUriString(string? uriString, UriKind uriKind);
static member IsWellFormedUriString : string * UriKind -> bool
Public Shared Function IsWellFormedUriString (uriString As String, uriKind As UriKind) As Boolean
參數
傳回
true如果弦是良好形成的;否則,。 false
備註
在 4.5 版本之前的 .NET 版本中,根據 RFC 2396 和 RFC 2732,該字串預設被視為良形。 若啟用國際資源識別碼(IRI)或國際化網域名稱(IDN)解析,該字串依據 RFC 3986 與 RFC 3987 被視為良構。
從 .NET 4.5 開始,字串依據 RFC 3986 和 RFC 3987,無論是否啟用 IRI 或 IDN,都被視為良形的。 不過請注意,這僅適用於針對 .NET 4.5 或更新版本的應用程式。 針對 .NET 4.0 的應用程式會呼叫相容性程式碼,並體驗舊有(4.5 前)的行為。
若出現以下任一條件,該字串被視為不良,導致方法回傳 false
| 錯誤 | 範例 |
|---|---|
| 弦未正確逃脫。 | http://www.contoso.com/path???/file name |
| 字串是一個 Uri 絕對字串,代表隱含檔案 Uri。 | c:\\directory\filename |
| 這串字串是絕對的 URI,路徑前少了一個斜線。 | file://c:/directory/filename |
| 字串包含未跳脫的反斜線,即使它們會被視為前斜線 | http:\\\host/path/file |
| 該字串代表一個階層式絕對 Uri ,且不包含「ˈ」 | www.contoso.com/path/file |
| 解析器 Scheme 表示原始字串並非良好形成。 | 範例依據 URI 的方案而定。 |
| 從 .NET 4.5 開始,首段冒號為 ':' 的相對 URI 不被視為良好形成。 | 2013.05.29_14:33:41 |
欲了解更多關於IRI支援的資訊,請參閱該 Uri 課程備註區。