Bahasa

HtmlTextWriter.EncodeUrl(String) Metode

Definisi

Melakukan pengodean URL minimal dengan mengonversi spasi di URL yang ditentukan ke string "%20".

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

Parameter

url
String

String yang berisi URL untuk dikodekan.

Mengembalikan

String yang berisi URL yang dikodekan.

Contoh

Contoh kode berikut menunjukkan cara memanggil EncodeUrl metode untuk mengonversi spasi apa pun di URL yang diteruskan sebagai parameter dalam AddAttribute panggilan metode.

// 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

Keterangan

Pengodean URL karakter terdiri dari simbol persen (%), diikuti oleh representasi heksadesimal dua digit (tidak peka huruf besar/kecil) dari titik kode ISO-Latin untuk karakter. Representasi heksadesimal dari ruang adalah 20.

Berlaku untuk

Lihat juga