URI 配置URI schemes

有幾個可供您用來參考您的應用程式套件、您的應用程式資料的資料夾或雲端之檔案的 URI (統一資源識別項) 配置。There are several URI (Uniform Resource Identifier) schemes that you can use to refer to files that come from your app's package, your app's data folders, or the cloud. 您也可以使用 URI 配置參考從您應用程式的檔案資源 (.resw) 載入的字串。You can also use a URI scheme to refer to strings loaded from your app's Resources Files (.resw). 您可以在程式碼、XAML 標記、應用程式套件資訊清單或磚及快顯通知範本中使用這些 URI 配置。You can use these URI schemes in your code, in your XAML markup, in your app package manifest, or in your tile and toast notification templates.

URI 配置的一般功能Common features of the URI schemes

本主題說明的所有配置都遵循正規化及資源擷取的一般 URI 配置規則。All of the schemes described in this topic follow typical URI scheme rules for normalization and resource retrieval. 如需了解 URI 的一般語法,請參閱 RFC 3986See RFC 3986 for the generic syntax of a URI.

所有的 URI 配置都會根據 RFC 3986 將階層式組件定義為 URI 的授權單位及路徑元件。All of the URI schemes define the hierarchical part per RFC 3986 as the authority and path components of the URI.

URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part   = "//" authority path-abempty
            / path-absolute
            / path-rootless
            / path-empty

這表示,URI 基本上會有三個元件。What this means is that there are essentially three components to a URI. 緊接在 URI 配置的兩個斜線後面的是稱為授權單位的元件 (可空白)。Immediately following the two forward slashes of the URI scheme is a component (which can be empty) called the authority. 再緊接其後的是路徑And immediately following that is the path. 以 URI http://www.contoso.com/welcome.png 為例,其配置是「http://」、授權單位是「www.contoso.com」,以及路徑是「/welcome.png」。Taking the URI http://www.contoso.com/welcome.png as an example, the scheme is "http://", the authority is "www.contoso.com", and the path is "/welcome.png". 另舉一個範例 URI ms-appx:///logo.png,其中授權單位元件為空白,並接受預設值。Another example is the URI ms-appx:///logo.png, where the authority components is empty and takes a default value.

本主題所述 URI 的配置特定處理會忽略片段元件。The fragment component is ignored by the scheme-specific processing of the URIs mentioned in this topic. 進行資源擷取和比較時,片段元件並無任何影響。During resource retrieval and comparison, the fragment component has no bearing. 不過,特定實作以上的層級可能會解譯片段來擷取次要資源。However, layers above specific implementation may interpret the fragment to retrieve a secondary resource.

正規化所有 IRI 元件之後,會進行位元組對位元組的比較。Comparison occurs byte for byte after normalization of all IRI components.

不區分大小寫和正規化Case-insensitivity and normalization

本主題說明的所有 URI 配置都遵循配置正規化及資源擷取的一般 URI 規則 (RFC 3986)。All the URI schemes described in this topic follow typical URI rules (RFC 3986) for normalization and resource retrieval for schemes. 這些標準化形式的 URI 會維持大小寫,並對 RFC 3986 非保留字元進行百分比解碼。The normalized form of these URIs maintains case and percent-decodes RFC 3986 unreserved characters.

就本主題所述的所有 URI 配置而言,配置授權單位路徑依照標準不區分大小寫,或是由其他系統以不區分大小寫的方式來處理。For all the URI schemes described in this topic, scheme, authority, and path are either case-insensitive by standard, or else are processed by the system in a case-insensitive way. 注意:該規則的唯一例外是 ms-resource授權單位,這會區分大小寫。Note The only exception to that rule is the authority of ms-resource, which is case-sensitive.

ms-appx 和 ms-appx-webms-appx and ms-appx-web

使用 ms-appxms-appx-web URI 配置來參考應用程式套件中的檔案 (請參閱封裝應用程式)。Use the ms-appx or the ms-appx-web URI scheme to refer to a file that comes from your app's package (see Packaging apps). 應用程式套件中的檔案通常是靜態影像、資料、程式碼及配置檔案。Files in your app package are typically static images, data, code, and layout files. ms-appx-web 配置將相同的檔案當做 ms-appx 來存取,但會在網頁區間中進行。The ms-appx-web scheme accesses the same files as ms-appx, but in the web compartment. 如需詳細資訊,請參閱從 XAML 標記和程式碼參考影像或其他資產For examples and more info, see Reference an image or other asset from XAML markup and code.

配置名稱 (ms-appx 和 ms-appx-web)Scheme name (ms-appx and ms-appx-web)

URI 配置名稱是字串 "ms-appx" 或 "ms-appx-web"。The URI scheme name is the string "ms-appx" or "ms-appx-web".

ms-appx://
ms-appx-web://

授權單位 (ms-appx 和 ms-appx-web)Authority (ms-appx and ms-appx-web)

授權單位是封裝資訊清單中定義的套件識別名稱。The authority is the package identity name that is defined in the package manifest. 因此受限於套件識別名稱中所允許之字元集的 URI 和 IRI (國際化資源識別項) 形式。It is therefore limited in both the URI and IRI (Internationalized resource identifier) form to the set of characters allowed in a package identity name. 套件名稱必須是在目前執行中應用程式的套件相依性關係圖上,其中一個套件的名稱。The package name must be the name of one of the packages in the current running app's package dependency graph.

ms-appx://Contoso.MyApp/
ms-appx-web://Contoso.MyApp/

如果授權單位中出現任何其他字元,則擷取和比較會失敗。If any other character appears in the authority, then retrieval and comparison fail. 授權單位的預設值是目前執行中應用程式的套件。The default value for the authority is the currently running app's package.

ms-appx:///
ms-appx-web:///

使用者資訊和連接埠 (ms-appx 和 ms-appx-web)User info and port (ms-appx and ms-appx-web)

與其他常用配置不同,ms-appx 配置不會定義使用者資訊或連接埠元件。The ms-appx scheme, unlike other popular schemes, does not define a user info or port component. 由於不允許 "@" and ":" 做為有效授權單位值,如果有包含,查閱會失敗。Since "@" and ":" are not allowed as valid authority values, lookup will fail if they are included. 下列各項會失敗。Each of the following fails.

ms-appx://john@contoso.myapp/default.html
ms-appx://john:password@contoso.myapp/default.html
ms-appx://contoso.myapp:8080/default.html
ms-appx://john:password@contoso.myapp:8080/default.html

路徑 (ms-appx 和 ms-appx-web)Path (ms-appx and ms-appx-web)

路徑元件符合一般 RFC 3986 語法,並且支援在 IRI 中使用非 ASCII 字元。The path component matches the generic RFC 3986 syntax and supports non-ASCII characters in IRIs. 路徑元件定義檔案的邏輯或實體檔案路徑。The path component defines the logical or physical file path of a file. 該檔案位於與授權單位指定應用程式之應用程式套件安裝位置相關聯的資料夾中。That file is in a folder associated with the installed location of the app package, for the app specified by the authority.

如果路徑參考實體路徑及檔案名稱,則擷取該實體檔案資產。If the path refers to a physical path and file name then that physical file asset is retrieved. 但如果不找到這樣的實體檔案,則在執行階段使用內容交涉來決定擷取期間傳回的實際資源。But if no such physical file is found then the actual resource returned during retrieval is determined by using content negotiation at runtime. 這項決定以應用程式、作業系統和使用者設定 (例如語言、顯示縮放比例、佈景主題、高對比及其他執行階段內容) 為根據。This determination is based on app, OS, and user settings such as language, display scale factor, theme, high contrast, and other runtime contexts. 例如,決定要擷取的實際資源值時,可以將應用程式語言、系統顯示設定與使用者高對比設定的組合列入考慮。For example, a combination of the app's languages, the system's display settings, and the user's high contrast settings may be taken into account when determining the actual resource value to be retrieved.

ms-appx:///images/logo.png

上述 URI 可能會實際擷取目前應用程式套件中具有下列實體檔案名稱的檔案。The URI above may actually retrieve a file within the current app's package with the following physical file name.

\Images\fr-FR\logo.scale-100_contrast-white.png

當然也可以直接以其完整名稱參考這個相同的實體檔案來進行擷取。You could of course also retrieve that same physical file by referring to it directly by its full name.

<Image Source="ms-appx:///images/fr-FR/logo.scale-100_contrast-white.png"/>

ms-appx(-web) 的路徑元件和一般 URI 一樣會區分大小寫。The path component of ms-appx(-web) is, like generic URIs, case sensitive. 不過,當存取資源的基礎檔案系統不區分大小寫時 (例如 NTFS),則是以不區分大小寫的方式進行擷取。However, when the underlying file system by which the resource is accessed is case insensitive, such as for NTFS, the retrieval of the resource is done case-insensitively.

標準化形式的 URI 會維持大小寫,並對 RFC 3986 非保留字元進行百分比解碼 ("%" 符號後面加上兩位數十六進位表示)。The normalized form of the URI maintains case, and percent-decodes (a "%" symbol followed by the two-digit hexadecimal representation) RFC 3986 unreserved characters. 字元 "?"、"#"、"/"、"*" 和 ' "' (雙引號字元) 必須在路徑中以百分比編碼,以代表資料,例如檔案或資料夾名稱。The characters "?", "#", "/", "*", and '"' (the double-quote character) must be percent-encoded in a path to represent data such as file or folder names. 所有百分比編碼字元都會在擷取前進行解碼。All percent-encoded characters are decoded before retrieval. 因此,若要擷取名稱為 Hello#World.html 的檔案,請使用這個 URI。Thus, to retrieve a file named Hello#World.html, use this URI.

ms-appx:///Hello%23World.html

查詢 (ms-appx 和 ms-appx-web)Query (ms-appx and ms-appx-web)

進行資源擷取時會忽略查詢參數。Query parameters are ignored during retrieval of resources. 標準化形式的查詢參數會維持大小寫。The normalized form of query parameters maintains case. 進行比較時會忽略查詢參數。Query parameters are not ignored during comparison.

ms-appdatams-appdata

使用 ms-appdata URI 配置來參考來自應用程式本機、漫遊以及暫存資料之資料夾的檔案。Use the ms-appdata URI scheme to refer to files that come from the app's local, roaming, and temporary data folders. 如需有關這些應用程式資料之資料夾的詳細資訊,請參閱儲存及擷取設定和其他應用程式資料For more info about these app data folders, see Store and retrieve settings and other app data.

ms-appdata URI 配置不會執行 ms-appx 和 ms-appx-web 所做的執行階段內容交涉。The ms-appdata URI scheme does not perform the runtime content negotiation that ms-appx and ms-appx-web do. 但是您可以回應 ResourceContext.QualifierValues 的內容,並在 URI 中使用完整實體檔案名稱,從應用程式資料載入適當的資產。But you can respond to the contents of ResourceContext.QualifierValues and load the appropriate assets from app data using their full physical file name in the URI.

配置名稱 (ms-appdata)Scheme name (ms-appdata)

URI 配置名稱是字串 "ms-appdata"。The URI scheme name is the string "ms-appdata".

ms-appdata://

授權單位 (ms-appdata)Authority (ms-appdata)

授權單位是封裝資訊清單中定義的套件識別名稱。The authority is the package identity name that is defined in the package manifest. 因此受限於套件識別名稱中所允許之字元集的 URI 和 IRI (國際化資源識別項) 形式。It is therefore limited in both the URI and IRI (Internationalized resource identifier) form to the set of characters allowed in a package identity name. 套件名稱必須是目前執行中應用程式套件的名稱。The package name must be the name of the current running app's package.

ms-appdata://Contoso.MyApp/

如果授權單位中出現任何其他字元,則擷取和比較會失敗。If any other character appears in the authority, then retrieval and comparison fail. 授權單位的預設值是目前執行中應用程式的套件。The default value for the authority is the currently running app's package.

ms-appdata:///

使用者資訊和連接埠 (ms-appdata)User info and port (ms-appdata)

與其他常用配置不同,ms-appdata 配置不會定義使用者資訊或連接埠元件。The ms-appdata scheme, unlike other popular schemes, does not define a user info or port component. 由於不允許 "@" and ":" 做為有效授權單位值,如果有包含,查閱會失敗。Since "@" and ":" are not allowed as valid authority values, lookup will fail if they are included. 下列各項會失敗。Each of the following fails.

ms-appdata://john@contoso.myapp/local/data.xml
ms-appdata://john:password@contoso.myapp/local/data.xml
ms-appdata://contoso.myapp:8080/local/data.xml
ms-appdata://john:password@contoso.myapp:8080/local/data.xml

路徑 (ms-appdata)Path (ms-appdata)

路徑元件符合一般 RFC 3986 語法,並且支援在 IRI 中使用非 ASCII 字元。The path component matches the generic RFC 3986 syntax and supports non-ASCII characters in IRIs. Windows.Storage.ApplicationData 位置中,有三個保留作本機、漫遊及暫時狀態儲存區的資料夾。Within the Windows.Storage.ApplicationData location are three reserved folders for local, roaming, and temporary state storage. ms-appdata 配置允許存取這些位置中的檔案及資料夾。The ms-appdata scheme allows access to files and folders in those locations. 路徑元件的第一個區段必須以下列方式指定特定資料夾。The first segment of the path component must specify the particular folder in the following fashion. 因此「路徑空白」形式的「階層組件」不合法。Thus the "path-empty" form of "hier-part" is not legal.

本機資料夾。Local folder.

ms-appdata:///local/

暫存資料夾。Temporary folder.

ms-appdata:///temp/

漫遊資料夾。Roaming folder.

ms-appdata:///roaming/

ms-appdata 的路徑元件和一般 URI 一樣會區分大小寫。The path component of ms-appdata is, like generic URIs, case sensitive. 不過,當存取資源的基礎檔案系統不區分大小寫時 (例如 NTFS),則是以不區分大小寫的方式進行擷取。However, when the underlying file system by which the resource is accessed is case insensitive, such as for NTFS, the retrieval of the resource is done case-insensitively.

標準化形式的 URI 會維持大小寫,並對 RFC 3986 非保留字元進行百分比解碼 ("%" 符號後面加上兩位數十六進位表示)。The normalized form of the URI maintains case, and percent-decodes (a "%" symbol followed by the two-digit hexadecimal representation) RFC 3986 unreserved characters. 字元 "?"、"#"、"/"、"*" 和 ' "' (雙引號字元) 必須在路徑中以百分比編碼,以代表資料,例如檔案或資料夾名稱。The characters "?", "#", "/", "*", and '"' (the double-quote character) must be percent-encoded in a path to represent data such as file or folder names. 所有百分比編碼字元都會在擷取前進行解碼。All percent-encoded characters are decoded before retrieval. 因此,若要擷取名稱為 Hello#World.html 的本機檔案,請使用這個 URI。Thus, to retrieve a local file named Hello#World.html, use this URI.

ms-appdata://local/Hello%23World.html

資源的擷取以及最上層路徑區段的識別是在點正規化之後進行處理 (「.././b/c」)。Retrieval of the resource, and identification of the top level path segment, are handled after normalization of dots (".././b/c"). 因此,URI 無法透過以點替代其中一個保留資料夾的方式來表示其本身。Therefore, URIs cannot dot themselves out of one of the reserved folders. 因此,不允許下列 URI。Thus, the following URI is not allowed.

ms-appdata:///local/../hello/logo.png

但允許這個 URI (即使很冗長)。But this URI is allowed (albeit redundant).

ms-appdata:///local/../roaming/logo.png

查詢 (ms-appdata)Query (ms-appdata)

進行資源擷取時會忽略查詢參數。Query parameters are ignored during retrieval of resources. 標準化形式的查詢參數會維持大小寫。The normalized form of query parameters maintains case. 進行比較時會忽略查詢參數。Query parameters are not ignored during comparison.

ms-resourcems-resource

使用 ms-resource URI 配置參考從應用程式資源檔案 (.resw) 載入的字串。Use the ms-resource URI scheme to refer to strings loaded from your app's Resources Files (.resw). 如需資源檔案的範例及詳細資訊,請參閱將 UI 及應用程式套件資訊清單中的字串當地語系化For examples and more info about Resources Files, see Localize strings in your UI and app package manifest.

配置名稱 (ms-resource)Scheme name (ms-resource)

URI 配置名稱是字串 "ms-resource"。The URI scheme name is the string "ms-resource".

ms-resource://

授權單位 (ms-resource)Authority (ms-resource)

授權單位是封裝資源索引 (PRI) 中定義的最上層資源對應,通常對應至封裝資訊清單中的定義的套件識別名稱。The authority is the top-level resource map defined in the Package Resource Index (PRI), which typically corresponds to the package identity name that is defined in the package manifest. 請參閱 封裝應用程式) 。See Packaging apps). 因此受限於套件識別名稱中所允許之字元集的 URI 和 IRI (國際化資源識別項) 形式。It is therefore limited in both the URI and IRI (Internationalized resource identifier) form to the set of characters allowed in a package identity name. 套件名稱必須是在目前執行中應用程式的套件相依性關係圖上,其中一個套件的名稱。The package name must be the name of one of the packages in the current running app's package dependency graph.

ms-resource://Contoso.MyApp/
ms-resource://Microsoft.WinJS.1.0/

如果授權單位中出現任何其他字元,則擷取和比較會失敗。If any other character appears in the authority, then retrieval and comparison fail. 授權單位的預設值是目前執行中應用程式的區分大小寫套件名稱。The default value for the authority is the case-sensitive package name of the currently running app.

ms-resource:///

授權單位會區分大小寫,而且標準化形式也會維持大小寫。The authority is case sensitive, and the normalized form maintains its case. 不過,查閱資源時是以不區分大小寫的方式進行。Lookup of a resource, however, happens case-insensitively.

使用者資訊和連接埠 (ms-resource)User info and port (ms-resource)

與其他常用配置不同,ms-resource 配置不會定義使用者資訊或連接埠元件。The ms-resource scheme, unlike other popular schemes, does not define a user info or port component. 由於不允許 "@" and ":" 做為有效授權單位值,如果有包含,查閱會失敗。Since "@" and ":" are not allowed as valid authority values, lookup will fail if they are included. 下列各項會失敗。Each of the following fails.

ms-resource://john@contoso.myapp/Resources/String1
ms-resource://john:password@contoso.myapp/Resources/String1
ms-resource://contoso.myapp:8080/Resources/String1
ms-resource://john:password@contoso.myapp:8080/Resources/String1

路徑 (ms-resource)Path (ms-resource)

路徑會識別 ResourceMap 樹狀子目錄的階層位置 (請參閱資源管理系統) 以及其中的 NamedResourceThe path identifies the hierarchical location of the ResourceMap subtree (see Resource Management System) and the NamedResource within it. 這通常對應至資源檔案 (.resw) 的檔名 (不含副檔名),以及其中字串資源的識別碼。Typically, this corresponds to the filename (excluding extension) of a Resources Files (.resw) and the identifier of a string resource within it.

如需範例及詳細資訊,請參閱將 UI 及應用程式套件資訊清單中的字串當地語系化對語言、縮放比例及高對比的磚和快顯通知支援For examples and more info, see Localize strings in your UI and app package manifest and Tile and toast notification support for language, scale, and high contrast.

ms-resource 的路徑元件和一般 URI 一樣會區分大小寫。The path component of ms-resource is, like generic URIs, case sensitive. 不過,基礎抓取會執行 CompareStringOrdinal ,並將 ignoreCase 設定為 trueHowever, the underlying retrieval does a CompareStringOrdinal with ignoreCase set to true.

標準化形式的 URI 會維持大小寫,並對 RFC 3986 非保留字元進行百分比解碼 ("%" 符號後面加上兩位數十六進位表示)。The normalized form of the URI maintains case, and percent-decodes (a "%" symbol followed by the two-digit hexadecimal representation) RFC 3986 unreserved characters. 字元 "?"、"#"、"/"、"*" 和 ' "' (雙引號字元) 必須在路徑中以百分比編碼,以代表資料,例如檔案或資料夾名稱。The characters "?", "#", "/", "*", and '"' (the double-quote character) must be percent-encoded in a path to represent data such as file or folder names. 所有百分比編碼字元都會在擷取前進行解碼。All percent-encoded characters are decoded before retrieval. 因此,若要從名為的資源檔取出字串資源 Hello#World.resw ,請使用此 URI。Thus, to retrieve a string resource from a Resources File named Hello#World.resw, use this URI.

ms-resource:///Hello%23World/String1

查詢 (ms-resource)Query (ms-resource)

進行資源擷取時會忽略查詢參數。Query parameters are ignored during retrieval of resources. 標準化形式的查詢參數會維持大小寫。The normalized form of query parameters maintains case. 進行比較時會忽略查詢參數。Query parameters are not ignored during comparison. 查詢參數是以區分大小寫的方式進行比較。Query parameters are compared case-sensitively.

層級在此 URI 剖析以上之特定元件的開發人員可能會選擇依照自認合適的方式使用查詢參數。Developers of particular components layered above this URI parsing may choose to use the query parameters as they see fit.