del método HtmlValidationContext.ValidateLinkValue
Tiras no seguras o no permitidos las direcciones URL y HTML marcado y devuelve un objeto validado LinkFieldValue .
Espacio de nombres: Microsoft.SharePoint.Publishing.Fields
Ensamblado: Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)
Sintaxis
'Declaración
Public Function ValidateLinkValue ( _
linkValue As LinkFieldValue, _
<OutAttribute> ByRef tagsWereDropped As Boolean, _
<OutAttribute> ByRef urlsWereDropped As Boolean _
) As LinkFieldValue
'Uso
Dim instance As HtmlValidationContext
Dim linkValue As LinkFieldValue
Dim tagsWereDropped As Boolean
Dim urlsWereDropped As Boolean
Dim returnValue As LinkFieldValue
returnValue = instance.ValidateLinkValue(linkValue, _
tagsWereDropped, urlsWereDropped)
public LinkFieldValue ValidateLinkValue(
LinkFieldValue linkValue,
out bool tagsWereDropped,
out bool urlsWereDropped
)
Parámetros
linkValue
Tipo: Microsoft.SharePoint.Publishing.Fields.LinkFieldValueEl objeto LinkFieldValue que se va a validar.
tagsWereDropped
Tipo: System.BooleanDevolución, este parámetro se establece a True si las etiquetas no permitidas se encuentra y se quita durante la validación. De lo contrario, se establece en False.
urlsWereDropped
Tipo: System.BooleanDevolución, este parámetro se establece a True si se encontraron todas las direcciones URL no permitida y eliminan durante la validación de lo contrario, establecer en False.
Valor devuelto
Tipo: Microsoft.SharePoint.Publishing.Fields.LinkFieldValue
El objeto validado LinkFieldValue desde la que se ha quitado todo el contenido no seguro o no permitido.
Comentarios
Quita las etiquetas, atributos o marcado de un objeto LinkFieldValue que no son seguros o no se ajustan a la configuración de restricción que se han aplicado a este objeto HtmlValidationContext .
Las siguientes propiedades no afectan a este método: AllowFonts, AllowHeadings, AllowLists, AllowReusableContent, AllowTablesy AllowTextMarkup.
Pueden establecer las propiedades AllowImages y RestrictUrlsToSiteCollection a True o False.
Ejemplos
En este ejemplo se crea un objeto HtmlValidationContext y lo utiliza para restringir y validar un objeto de LinkFieldValue y devuelven una cadena de informe. La muestra la función toma dos argumentos opcionales:
linkValue. Un objeto LinkFieldValue para ejecutarse a través de la validación. Si este argumento está vacío, a continuación, la aplicación utiliza un objeto de LinkFieldValue predeterminado.
siteCollectionToRestrict. Un objeto SPSite a utilizar para restringir las direcciones URL en HTML. Si este argumento es null las direcciones URL no están restringidas a un SPSite.
// ValidateLinkValueSample
using SPSite = Microsoft.SharePoint.SPSite;
using ImageFieldValue = Microsoft.SharePoint.Publishing.Fields.ImageFieldValue;
using LinkFieldValue = Microsoft.SharePoint.Publishing.Fields.LinkFieldValue;
using ImageFieldValue = Microsoft.SharePoint.Publishing.Fields.ImageFieldValue;
using LinkFieldValue = Microsoft.SharePoint.Publishing.Fields.LinkFieldValue;
using HtmlValidationContext = Microsoft.SharePoint.Publishing.Fields.HtmlValidationContext;
namespace Microsoft.SDK.SharePointServer.Samples
{
public static string ValidateLinkValueSample(
LinkFieldValue linkValue,
SPSite siteCollectionToRestrict)
{
LinkFieldValue linkValueToValidate = linkValue;
// If there is no provided value then construct a new default value
if (null == linkValueToValidate)
{
linkValueToValidate = new LinkFieldValue();
linkValueToValidate.NavigateUrl = DefaultHyperlink;
linkValueToValidate.Text = LinkFieldValue.GetDefaultDisplayText(DefaultHyperlink);
}
string reportString = "Validating the following link value \n[" + linkValueToValidate.ToString() + "]";
HtmlValidationContext validationContext = new HtmlValidationContext();
if (null == siteCollectionToRestrict)
{
// No site collection provided so do not restrict URLs
validationContext.RestrictUrlsToSiteCollection = false;
validationContext.GuidOfThisSiteCollection = System.Guid.Empty;
}
else
{
// Restrict URLs to be from the provided site collection or to be server relative
validationContext.RestrictUrlsToSiteCollection = true;
validationContext.GuidOfThisSiteCollection = siteCollectionToRestrict.ID;
}
bool droppedTags;
bool droppedUrls;
LinkFieldValue validatedValue =
validationContext.ValidateLinkValue(
linkValueToValidate,
out droppedTags,
out droppedUrls);
reportString += "\nAfter validation we have the following link value \n[" + validatedValue.ToString() + "]";
return reportString;
}
}
}