Freigeben über


HtmlTextWriter.EncodeUrl-Methode

Führt eine minimale URL-Codierung durch, indem Leerzeichen im angegebenen URL in die Zeichenfolge "%20" konvertiert werden.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Protected Function EncodeUrl ( _
    url As String _
) As String
'Usage
Dim url As String
Dim returnValue As String

returnValue = Me.EncodeUrl(url)
protected string EncodeUrl (
    string url
)
protected:
String^ EncodeUrl (
    String^ url
)
protected String EncodeUrl (
    String url
)
protected function EncodeUrl (
    url : String
) : String

Parameter

  • url
    Eine Zeichenfolge, die den zu codierenden URL enthält.

Rückgabewert

Eine Zeichenfolge, die den codierten URL enthält.

Hinweise

Die URL-Codierung eines Zeichens besteht aus einem Prozentsymbol (%) gefolgt von einer zweistelligen Hexadezimaldarstellung (ohne Berücksichtigung von Groß- und Kleinschreibung) des ISO-Lateinisch-Codepunktes für das Zeichen. Die Hexadezimaldarstellung eines Leerzeichens ist 20.

Beispiel

Im folgenden Codebeispiel wird der Aufruf der EncodeUrl-Methode zum Konvertieren aller Leerzeichen in dem URL, der als Parameter in einem AddAttribute-Methodenaufruf übergeben wird, veranschaulicht.

' 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
// 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 being 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 (get_TagKey().Equals(HtmlTextWriterTag.A)) {
    if (!(IsAttributeDefined(HtmlTextWriterAttribute.Href))) {
        AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
    }
}

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlTextWriter-Klasse
HtmlTextWriter-Member
System.Web.UI-Namespace
TextWriter
UrlPathEncode
AddAttribute
HttpRequest