HtmlTextWriter.EncodeUrl(String) Metod

Definition

Utför minimal URL-kodning genom att konvertera blanksteg i den angivna URL:en till strängen "%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

Parametrar

url
String

En sträng som innehåller URL:en som ska kodas.

Returer

En sträng som innehåller den kodade URL:en.

Exempel

I följande kodexempel visas hur du anropar EncodeUrl metoden för att konvertera blanksteg i den URL som skickas som en parameter i ett AddAttribute metodanrop.

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

Kommentarer

URL-kodning av ett tecken består av en procentsymbol (%), följt av den tvåsiffriga hexadecimala representationen (skiftlägesokänslig) av ISO-Latin kodpunkt för tecknet. Den hexadecimala representationen av ett utrymme är 20.

Gäller för

Se även