最近发现用户在从网上复制数据然后粘贴入OA,添加数据时报错~比如复制几个字“为革命,保护视力”,粘贴后变成“为革命,保护视力  ”,本以为是多了个空格,但跟踪查看后发现是“燩”,十分费解,,,,,不知是何原因????

解决方案 »

  1.   

    单步调试看看数据
    过滤
    在后台设置过滤字符
    void Application_BeginRequest(object sender, EventArgs e)
    {
      for (int i=0; i < Request.Form.Count;i++)
      {
      if (Request.Form[i].ToString() == "__VIEWSTATE") continue;
      if (IsM(Request.Form[i].ToString()))
      {
      Response.Write("您提交的内容中含有非法字符.");
      Response.End();
      }  }  
    }
    protected bool IsM(string InText)
    {
      string word = @"";
      if (InText == null)
      return false;
      if (Regex.IsMatch(InText,word))
      return true;
      return false;
    }  
      

  2.   


    木有看明白:
    protected bool IsM(string InText)
    {
      string word = @"";
      if (InText == null)
      return false;
      if (Regex.IsMatch(InText,word))
      return true;
      return false;
    }   
    难道"燩"就是个空格???
      

  3.   

    /// <summary>
        /// 过滤输入信息
        /// </summary>
        /// <param name="text">内容</param>
        /// <param name="maxLength">最大长度</param>
        /// <returns></returns>
        /// 替换不正常字符
        /// 记得引用 using System.Text.RegularExpressions;
        public static string InputText(string text, int maxLength)
        {
            #region
            text = text.Trim();
            if (string.IsNullOrEmpty(text))
                return string.Empty;
            if (text.Length > maxLength)
                text = text.Substring(0, maxLength);
            text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces
            text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br>
            text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //&nbsp;
            text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags
            text = text.Replace("'", "''");
            return text;
            #endregion
        }
      

  4.   

    说实话,我也替换过了,数据存储类型为ntext,可就是替不了“燩”, 它在输入框中看不到,是以空格的形式存在,只有在断点跟入时才看到它,但也就报错了~
      

  5.   

    使用一个文本编辑器吧  不知道你使用的是不是  这个通常不会出错的 哪怕有特殊字符   要是不行的话 你试试 用trim()  应该可以的 
      

  6.   

    是否编码的问题呢?
    SQL Server 的处理可以在字符串前加N
      

  7.   

    怎么直接把PetShop的代码贴过来了…
      

  8.   

    如果是登陆或者注册的话可以看看web.config文件中Membership配置节中的内容。
      

  9.   

    就算是一个textbox中用户输入了乱码,也不至于运行出错吧?难道我真的out了