aspnet过滤特殊字符
㈠ c#文本框如何存储三次方等特殊字符
用富文本框 或网页控件吧 自己处理文字大小及位置 复杂的可以用图片
㈡ c# 如何编写出想word文档似的特殊字符的对话框(从。txt文件中调用)
FontDialog fontDialog1 = new FontDialog ( ) ;
fontDialog1.ShowColor = true ;
fontDialog1.AllowScriptChange = false ;
if ( fontDialog1.ShowDialog ( ) != DialogResult.Cancel )
{
fnt = fontDialog1.Font ;
showInfo ( ) ;
}
㈢ .net 里怎么去掉特殊字符
你的JSON数据 从何而来, 从源头上解决这个问题。
㈣ 在asp.net传递参数怎么过滤特殊字符
SafeRequest=ParaValue
有问题吧。。
不能这样写。。。
str="abcdefgh..12304567890"
'符合你标准的字符
strs=你要过滤的字符
lens=len(strs)
for
i=1
to
lens
if
instr(strs,mod(str,i,1))=0
then
很不专幸字符不符合规则
这里是其他代码属
end
if
next
你也可以该成函数~~~~
㈤ 在.net中怎么样过滤地址栏特殊字符
||using System;
using System.Text.Regularexpression_rs;
using System.Web; bitscn_com
namespace FSqlKeyWord{
/// <summary>
/// SqlKey 的摘要说明。
/// </summary>
public class SqlKey{
private HttpRequest request;
private const string StrKeyWord = @"select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec master|netlocalgroup administrators|:|net user|""|or|and";
private const string StrRegex = @"[-|;|,|/|(|)|[|]|}|{|%|@|*|!|']";
public SqlKey(System.Web.HttpRequest _request){
//
// TODO: 在此处添加构造函数逻辑
//
this.request = _request;
}
/// <summary>
/// 只读属性 SQL关键字
/// </summary>
public static string KeyWord{
get{
return StrKeyWord;
}
}
/// <summary>
/// 只读属性过滤特殊字符
/// </summary>
public static string RegexString{
get{
return StrRegex;
}
}
/// <summary>
/// 检查URL参数中是否带有SQL注入可能关键字。
/// </summary>
/// <param name="_request">当前HttpRequest对象</param>
/// <returns>存在SQL注入关键字true存在,false不存在</returns>
public bool CheckRequestQuery(){
if (request.QueryString.Count != 0){
//若URL中参数存在,逐个比较参数。
for (int i = 0; i < request.QueryString.Count; i++){
// 检查参数值是否合法。
if (CheckKeyWord(request.QueryString[i].ToString())){
return true;
}
}
}
return false;
}
/// <summary>
/// 检查提交表单中是否存在SQL注入可能关键字
/// </summary>
/// <param name="_request">当前HttpRequest对象</param>
/// <returns>存在SQL注入关键字true存在,false不存在</returns>
public bool CheckRequestForm(){
if (request.Form.Count > 0){
//获取提交的表单项不为0 逐个比较参数
for (int i = 0; i < request.Form.Count; i++) {
//检查参数值是否合法
if (CheckKeyWord(request.Form[i])){
//存在SQL关键字
return true;
}
}
}
return false;
}
/// <summary>
/// 静态方法,检查_sword是否包涵SQL关键字
/// </summary>
/// <param name="_sWord">被检查的字符串</param>
/// <returns>存在SQL关键字返回true,不存在返回false</returns>
public static bool CheckKeyWord(string _sWord){
if (Regex.IsMatch(_sWord, StrKeyWord, RegexOptions.IgnoreCase) || Regex.IsMatch(_sWord, StrRegex))
return true;
return false;
}
/// <summary>
/// 反SQL注入:返回1无注入信息, 则返回错误处理
/// </summary>
/// <returns>返回1无注入信息,否则返回错误处理</returns>
public string CheckMessage(){
string msg = "1";
if (CheckRequestQuery()) //CheckRequestQuery() || CheckRequestForm(){
msg = "<span style='font-size:24px;'>非法操作!<br>";
msg += "操作IP:" + request.ServerVariables["REMOTE_ADDR"] + "<br>";
msg += "操作时间:" + DateTime.Now + "<br>";
msg += "页面:" + request.ServerVariables["URL"].ToLower() + "<br>";
msg += "<a href="#" onclick="history.back()">返回上一页</a></span>";
}
return msg.ToString();
}
}
}
㈥ C# 如何去掉string中所有转义字符(特殊符号)
1、去掉字符串中的转义等特殊字符:
stringinputString=@”helloworld]“;
StringBuildersb=newStringBuilder();
string[]parts=inputString.Split(newchar[]{’‘,‘ ’,‘ ’,‘ ’,‘f’,‘v’,’’},StringSplitOptions.RemoveEmptyEntries);
intsize=parts.Length;
for(inti=0;i<size;i++);
sb.AppendFormat(“{0}“,parts[i]);
2、删除字符串头尾的转义等特殊字符串:
使用SubString和Remove来操作
比如去掉结尾的转义字符,可以使用
inputString.SubString(0,inputString.Length-1);
inputString.SubString(0,inputString.Length-2);
inputString.SubString(0,inputString.Length-3);
(6)aspnet过滤特殊字符扩展阅读
C#字符串取消转义字符的转义作用,使其正常显示
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespacetest1
{
publicpartialclassForm2:Form
{
publicForm2()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstr=@"D:document est.txt";
stringstr1="D:\document\test.txt";
MessageBox.Show(str+"---"+str1);
}
}
}
㈦ c#中 如何将xml格式的字符串转封装成无特殊字符的字符串
你问这样的问题应该是在页面传值的时候出现安全困恼才提出吧
我常用的方法专,
如果是c#asp.net
编码属:Server.UrlEncode("xml");
解码:Server.UrlDecode("xml");
如果是javascript
编码:encodeURIComponent("xml");
解码:decodeURIComponent("xml");
这四个都是URL编码,通用,用于前后台传值可不担心安全提示问题本人推崇
㈧ 在asp.net传递参数怎么过滤特殊字符
1.传递前先加密 ,KEY是你自己定义的,加密解密函数KEY一致。
public static string Encode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(str);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(bytes, 0, bytes.Length);
stream2.FlushFinalBlock();
StringBuilder builder = new StringBuilder();
foreach (byte num in stream.ToArray())
{
builder.AppendFormat("{0:X2}", num);
}
stream.Close();
return builder.ToString();
}
2.获取参数后,解密
/// <summary>
/// Des 解密 GB2312
/// </summary>
/// <param name="str">Desc string</param>
/// <param name="key">Key ,必须为8位 </param>
/// <returns></returns>
public static string Decode(string str, string key)
{
try
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] buffer = new byte[str.Length / 2];
for (int i = 0; i < (str.Length / 2); i++)
{
int num2 = Convert.ToInt32(str.Substring(i * 2, 2), 0x10);
buffer[i] = (byte)num2;
}
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream.Close();
return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
}
catch (Exception)
{
return "";
}
}
㈨ c# 正则表达式 匹配特殊字符串“@$#%”
bool IsValidEmail(string strIn)
{
// Return true if strIn is in valid
return Regex.IsMatch(strIn, @"@$#%");
}