當前位置:首頁 » 凈水方式 » aspnet過濾特殊字元

aspnet過濾特殊字元

發布時間: 2021-01-12 02:41:38

㈠ 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, @"@$#%");
}

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239