HtmlTextWriter.EncodeUrl(String) Metoda

Definicja

Wykonuje minimalne kodowanie adresów URL, konwertując spacje w określonym adresie URL na ciąg "%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

Parametry

url
String

Ciąg zawierający adres URL do zakodowania.

Zwraca

String

Ciąg zawierający zakodowany adres URL.

Przykłady

W poniższym przykładzie kodu pokazano, jak wywołać metodę EncodeUrl w celu przekonwertowania dowolnych spacji w adresie URL przekazywanym jako parametr w wywołaniu AddAttribute metody.

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

Uwagi

Kodowanie adresu URL znaku składa się z symbolu procentu (%), po którym następuje dwucyfrowa reprezentacja szesnastkowa (bez uwzględniania wielkości liter) punktu kodu ISO-Latin znaku. Reprezentacja szesnastkowa przestrzeni wynosi 20.

Dotyczy

Zobacz też