HtmlTextWriter.EncodeUrl(String) メソッド

定義

指定した URL 内の空白文字列を "%20" に変換して、最小限の URL エンコーディングを実行します。

protected:
 System::String ^ EncodeUrl(System::String ^ url);
protected string EncodeUrl (string url);
member this.EncodeUrl : string -> string
Protected Function EncodeUrl (url As String) As String

パラメーター

url
String

エンコードする URL を格納している文字列。

戻り値

String

エンコードされた URL を格納している文字列。

次のコード例は、メソッドを呼び出して、メソッド呼び出し EncodeUrl でパラメーターとして渡される URL 内のスペースを変換する方法を AddAttribute 示しています。

// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if ( TagKey == HtmlTextWriterTag::A )
{
   if (  !IsAttributeDefined( HtmlTextWriterAttribute::Href ) )
   {
      AddAttribute( "href", EncodeUrl( "http://www.cohowinery.com" ) );
   }
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag.A)
{
    if (!IsAttributeDefined(HtmlTextWriterAttribute.Href))
    {
        AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
    }
}
' If an <anchor> element is rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href attribute
' and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
    If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
        AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
    End If
End If

注釈

文字の URL エンコードはパーセント記号 (%)で構成され、その後に文字のISO-Latinコード ポイントの 2 桁の 16 進数表現 (大文字と小文字は区別されません) が続きます。 スペースの 16 進数表現は 20 です。

適用対象

こちらもご覧ください