HtmlTextWriter.EncodeUrl(String) Methode

Definitie

Voert minimale URL-codering uit door spaties in de opgegeven URL te converteren naar de tekenreeks "%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

Parameters

url
String

Een tekenreeks die de URL bevat om te coderen.

Retouren

Een tekenreeks met de gecodeerde URL.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de EncodeUrl methode aanroept om spaties te converteren in de URL die wordt doorgegeven als parameter in een AddAttribute methodeaanroep.

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

Opmerkingen

URL-codering van een teken bestaat uit een procentsymbool (%), gevolgd door de hexadecimale weergave van twee cijfers (hoofdlettergevoelig) van het ISO-Latin codepunt voor het teken. De hexadecimale representatie van een spatie is 20.

Van toepassing op

Zie ook