HtmlTextWriter.EncodeUrl(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Realiza uma codificação mínima de URLs convertendo espaços na URL especificada para a cadeia "%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
Parâmetros
- url
- String
Uma string contendo o URL a codificar.
Devoluções
Uma cadeia que contém o URL codificado.
Exemplos
O exemplo de código seguinte demonstra como chamar o EncodeUrl método para converter quaisquer espaços na URL que seja passado como parâmetro numa AddAttribute chamada de método.
// 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
Observações
A codificação URL de um carácter consiste num símbolo percentual (%), seguido da representação hexadecimal de dois dígitos (indistinta a maiúsculas) do ISO-Latin ponto de código do carácter. A representação hexadecimal de um espaço é 20.