2010-09-14 74 views

回答

1
string keywords = Page 
    .Header 
    .Controls 
    .OfType<HtmlMeta>() 
    .Where(meta => string.Equals(meta.Name, "keywords", StringComparison.OrdinalIgnoreCase)) 
    .Select(meta => meta.Content) 
    .FirstOrDefault(); 
1

試試這個:

// Store the keywords here: 
List<String> keywords = new List<String>(); 
foreach (Control c in this.Page.Header.Controls) 
{ 
    HtmlMeta meta = c as HtmlMeta; 
    if (meta != null && 
      String.Compare(meta.Name, "keywords", true, CultureInfo.InvariantCulture) == 0) 
    { 
     // When it is a Keywords meta tag, split the contents on each komma 
     // and trim the spaces off. 
     string[] kwds = (meta.Content.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries); 
     foreach(string s in kwds) 
      keywords.Add(s.Trim()); 
    } 
} 
return keywords; 
相關問題