按一下以給予評分及指教
MSDN
MSDN Library
.NET 開發
.NET Framework
 UrlPathEncode 方法

  開啟低頻寬檢視
本頁僅適用於
Microsoft Visual Studio 2008/.NET Framework 3.5

其他版本也適用於下列軟體:
.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
社群內容   什麼是社群內容?
新增內容 RSS  註解
Processing
© 2009 Microsoft Corporation. 著作權所有,並保留一切權利。 使用規定  |  商標  |  隱私權聲明
Page view tracker