A.NET优化:Sql注入和Html注入的黑帽SEO.(3)_.NET概论及软件使用_龙虎鹰师网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN


作者:龙虎鹰师网安ASP维护基地 来源:龙虎鹰师网安ASP维护基地 浏览次数:0

本篇关键词:注入优化 string
龙虎鹰师网安网讯:    就直接上代码了:using System;using System.Text.RegularExpressions;/// <summary>/// NoFollow contains the functionality to add rel=nofollow to unstusted links/// </summary>p...


using System;
using System.Text.RegularExpressions;

/// <summary>
/// NoFollow contains the functionality to add rel=nofollow to unstusted links
/// </summary>
public static class NoFollow
  // the white list of domains (in lower case)
  private static string[] whitelist =    
     { "seoasp", "seoegghead.com">www.seoegghead.com", "www.cristiandarie.ro" };

  // finds all the links in the input string and processes them using fixLink
  public static string FixLinks(string input)
    // define the match evaluator
    MatchEvaluator fixThisLink = new MatchEvaluator(NoFollow.fixLink);

    // fix the links in the input string
    string fixedInput = Regex.Replace(input,

    // return the "fixed" input string
    return fixedInput;

  // receives a Regex match that contains a link such as
  // <a href="http://too.much.spam/"> and adds ref=nofollow if needed
  private static string fixLink(Match linkMatch)
    // retrieve the link from the received Match
    string singleLink = linkMatch.Value;

    // if the link already has rel=nofollow, return it back as it is
    if (Regex.IsMatch(singleLink,
      return singleLink;

    // use a named group to extract the URL from the link
    Match m = Regex.Match(singleLink,
    string url = m.Groups["url"].Value;

    // if URL doesn't contain http://, assume it's a local link
    if (!url.Contains("http://"))
      return singleLink;

    // extract the host name (such as www.cristiandarie.ro) from the URL
    Uri uri = new Uri(url);
    string host = uri.Host.ToLower();

    // if the host is in the whitelist, don't alter it
    if (Array.IndexOf(whitelist, host) >= 0)
      return singleLink;

    // if the URL already has a rel attribute, change its value to nofollow
    string newLink = Regex.Replace(singleLink,

    // if the string had a rel attribute that we changed, return the new link
    if (newLink != singleLink)
      return newLink;

    // if we reached this point, we need to add rel=nofollow to our link
    newLink = Regex.Replace(singleLink, "<a", @"<a rel=""nofollow""",
    return newLink;


网站维护教程更新时间:2012-03-30 05:24:49  【打印此页】  【关闭
全站连接N点 | 龙虎鹰师网安 |  

footer  footer  互联网安全  footer