.NET Framework 類別庫
HttpServerUtility..::.UrlPathEncode 方法

更新:2007 年 11 月

將 URL 字串的路徑部分以 URL 編碼,並傳回編碼的字串。

命名空間:  System.Web
組件:  System.Web (在 System.Web.dll 中)

語法

Visual Basic (宣告)
Public Function UrlPathEncode ( _
    s As String _
) As String
Visual Basic (使用方式)
Dim instance As HttpServerUtility
Dim s As String
Dim returnValue As String

returnValue = instance.UrlPathEncode(s)
C#
public string UrlPathEncode(
    string s
)
Visual C++
public:
String^ UrlPathEncode(
    String^ s
)
J#
public String UrlPathEncode(
    String s
)
JScript
public function UrlPathEncode(
    s : String
) : String

參數

s
型別:System..::.String

要作 URL 編碼的文字。

傳回值

型別:System..::.String

URL 編碼的文字。

備註

URL 編碼方式確保所有瀏覽器將會正確傳輸 URL 字串中的文字。此類的字元,例如問號 (?)、連字號 (&)、斜線符號 (/) 和空格在某些瀏覽器中可能會遭到截斷或毀損。因此,這些字元必須在 <a> 標記或查詢字串中編碼,而查詢字串中的字串可能是瀏覽器以要求字串所重新傳送。

UrlPathEncode 是在執行階段從 ASP.Net 應用程式存取 HttpUtility..::.UrlPathEncode 方法的一種很方便的方式。在內部,UrlPathEncode 使用 HttpUtility..::.UrlPathEncode 為字串編碼。

範例

下列範例會將字串以 URL 編碼,然後傳送到瀏覽器用戶端。在這個範例中,字串 MyURL 會編碼成 "http%3a%2f%2fwww.contoso.com%2farticles.aspx?title = ASP.NET Examples"。

Visual Basic
Dim MyURL As String
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples"

Response.Write( "<A HREF = " & Server.UrlPathEncode(MyURL) & "> ASP.NET Examples <br>")

C#
String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";

Response.Write( "<A HREF = " + Server.UrlPathEncode(MyURL) +  "> ASP.NET Examples <br>" );

J#
String myURL;
myURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples";
get_Response().Write(("<A HREF = " + get_Server().UrlPathEncode(myURL)
    + "> ASP.NET Examples <br>"));
JScript
var myURL : String
myURL = "http://www.contoso.com/articles.aspx?title = ASP.NET Examples"

Response.Write( "<A HREF = " + Server.UrlPathEncode(myURL) + "> ASP.NET Examples <br>")

平台

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.5、3.0、2.0、1.1、1.0
請參閱

參考

標記 :


Page view tracker