校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > HttpRequest的QueryString屬性 的一點認識

HttpRequest的QueryString屬性 的一點認識

熱門標簽:海外地圖標注門市標 山西防封卡電銷卡套餐 廈門商鋪地圖標注 地圖標注多個行程 上海楊浦怎么申請申請400電話 云南外呼電銷機器人系統 陜西人工外呼系統哪家好 銅川小型外呼系統運營商 浙江外呼系統怎么安裝
如:


當然我們一般都是按照提示來把framework版本設置2.0來解決。為什么可以這么解決了,還有沒有其它的解決方法了。
先讓我們看看QueryString的源代碼吧:
復制代碼 代碼如下:

public NameValueCollection QueryString
{
get
{
if (this._queryString == null)
{
this._queryString = new HttpValueCollection();
if (this._wr != null)
{
this.FillInQueryStringCollection();
}
this._queryString.MakeReadOnly();
}
if (this._flags[1])
{
this._flags.Clear(1);
this.ValidateNameValueCollection(this._queryString, RequestValidationSource.QueryString);
}
return this._queryString;
}
}
private void FillInQueryStringCollection()
{
byte[] queryStringBytes = this.QueryStringBytes;
if (queryStringBytes != null)
{
if (queryStringBytes.Length != 0)
{
this._queryString.FillFromEncodedBytes(queryStringBytes, this.QueryStringEncoding);
}
}
else if (!string.IsNullOrEmpty(this.QueryStringText))
{
this._queryString.FillFromString(this.QueryStringText, true, this.QueryStringEncoding);
}
}

  先讓我們插入一點 那就是QueryString默認已經做了url解碼。 其中HttpValueCollection的 FillFromEncodedBytes方法如下
復制代碼 代碼如下:

internal void FillFromEncodedBytes(byte[] bytes, Encoding encoding)
{
int num = (bytes != null) ? bytes.Length : 0;
for (int i = 0; i num; i++)
{
string str;
string str2;
this.ThrowIfMaxHttpCollectionKeysExceeded();
int offset = i;
int num4 = -1;
while (i num)
{
byte num5 = bytes[i];
if (num5 == 0x3d)
{
if (num4 0)
{
num4 = i;
}
}
else if (num5 == 0x26)
{
break;
}
i++;
}
if (num4 >= 0)
{
str = HttpUtility.UrlDecode(bytes, offset, num4 - offset, encoding);
str2 = HttpUtility.UrlDecode(bytes, num4 + 1, (i - num4) - 1, encoding);
}
else
{
str = null;
str2 = HttpUtility.UrlDecode(bytes, offset, i - offset, encoding);
}
base.Add(str, str2);
if ((i == (num - 1)) (bytes[i] == 0x26))
{
base.Add(null, string.Empty);
}
}
}

從這里我們可以看到QueryString已經為我們做了解碼工作,我們不需要寫成 HttpUtility.HtmlDecode(Request.QueryString["xxx"])而是直接寫成Request.QueryString["xxx"]就ok了。
現在讓我們來看看你QueryString的驗證,在代碼中有
復制代碼 代碼如下:

if (this._flags[1])
{
this._flags.Clear(1);
this.ValidateNameValueCollection(this._queryString, RequestValidationSource.QueryString);
}

一看this.ValidateNameValueCollection這個方法名稱就知道是干什么的了,驗證QueryString數據;那么在什么情況下驗證的了?
讓我們看看this._flags[1]在什么地方設置的:
復制代碼 代碼如下:

public void ValidateInput()
{
if (!this._flags[0x8000])
{
this._flags.Set(0x8000);
this._flags.Set(1);
this._flags.Set(2);
this._flags.Set(4);
this._flags.Set(0x40);
this._flags.Set(0x80);
this._flags.Set(0x100);
this._flags.Set(0x200);
this._flags.Set(8);
}
}

  而該方法在ValidateInputIfRequiredByConfig中調用,調用代碼
復制代碼 代碼如下:

internal void ValidateInputIfRequiredByConfig()
{
.........
if (httpRuntime.RequestValidationMode >= VersionUtil.Framework40)
{
this.ValidateInput();
}
}

我想現在大家都應該明白為什么錯題提示讓我們把framework改為2.0了吧。應為在4.0后才驗證。這種解決問題的方法是關閉驗證,那么我們是否可以改變默認的驗證規則了?
讓我們看看ValidateNameValueCollection
復制代碼 代碼如下:

private void ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
{
int count = nvc.Count;
for (int i = 0; i count; i++)
{
string key = nvc.GetKey(i);
if ((key == null) || !key.StartsWith("__", StringComparison.Ordinal))
{
string str2 = nvc.Get(i);
if (!string.IsNullOrEmpty(str2))
{
this.ValidateString(str2, key, requestCollection);
}
}
}
}
private void ValidateString(string value, string collectionKey, RequestValidationSource requestCollection)
{
int num;
value = RemoveNullCharacters(value);
if (!RequestValidator.Current.IsValidRequestString(this.Context, value, requestCollection, collectionKey, out num))
{
string str = collectionKey + "=\"";
int startIndex = num - 10;
if (startIndex = 0)
{
startIndex = 0;
}
else
{
str = str + "...";
}
int length = num + 20;
if (length >= value.Length)
{
length = value.Length;
str = str + value.Substring(startIndex, length - startIndex) + "\"";
}
else
{
str = str + value.Substring(startIndex, length - startIndex) + "...\"";
}
string requestValidationSourceName = GetRequestValidationSourceName(requestCollection);
throw new HttpRequestValidationException(SR.GetString("Dangerous_input_detected", new object[] { requestValidationSourceName, str }));
}
}
  
  哦?原來一切都明白了,驗證是在RequestValidator做的。
復制代碼 代碼如下:

public class RequestValidator
{
// Fields
private static RequestValidator _customValidator;
private static readonly LazyRequestValidator> _customValidatorResolver = new LazyRequestValidator>(new FuncRequestValidator>(RequestValidator.GetCustomValidatorFromConfig));
// Methods
private static RequestValidator GetCustomValidatorFromConfig()
{
HttpRuntimeSection httpRuntime = RuntimeConfig.GetAppConfig().HttpRuntime;
Type userBaseType = ConfigUtil.GetType(httpRuntime.RequestValidationType, "requestValidationType", httpRuntime);
ConfigUtil.CheckBaseType(typeof(RequestValidator), userBaseType, "requestValidationType", httpRuntime);
return (RequestValidator) HttpRuntime.CreatePublicInstance(userBaseType);
}
internal static void InitializeOnFirstRequest()
{
RequestValidator local1 = _customValidatorResolver.Value;
}
private static bool IsAtoZ(char c)
{
return (((c >= 'a') (c = 'z')) || ((c >= 'A') (c = 'Z')));
}
protected internal virtual bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
if (requestValidationSource == RequestValidationSource.Headers)
{
validationFailureIndex = 0;
return true;
}
return !CrossSiteScriptingValidation.IsDangerousString(value, out validationFailureIndex);
}
// Properties
public static RequestValidator Current
{
get
{
if (_customValidator == null)
{
_customValidator = _customValidatorResolver.Value;
}
return _customValidator;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_customValidator = value;
}
}
} 

主要的驗證方法還是在CrossSiteScriptingValidation.IsDangerousString(value, out validationFailureIndex);而CrossSiteScriptingValidation是一個內部類,無法修改。
讓我們看看CrossSiteScriptingValidation類大代碼把
復制代碼 代碼如下:

internal static class CrossSiteScriptingValidation
{
// Fields
private static char[] startingChars = new char[] { '', '' };
// Methods
private static bool IsAtoZ(char c)
{
return (((c >= 'a') (c = 'z')) || ((c >= 'A') (c = 'Z')));
}
internal static bool IsDangerousString(string s, out int matchIndex)
{
matchIndex = 0;
int startIndex = 0;
while (true)
{
int num2 = s.IndexOfAny(startingChars, startIndex);
if (num2 0)
{
return false;
}
if (num2 == (s.Length - 1))
{
return false;
}
matchIndex = num2;
char ch = s[num2];
if (ch != '')
{
if ((ch == '') ((IsAtoZ(s[num2 + 1]) || (s[num2 + 1] == '!')) || ((s[num2 + 1] == '/') || (s[num2 + 1] == '?'))))
{
return true;
}
}
else if (s[num2 + 1] == '#')
{
return true;
}
startIndex = num2 + 1;
}
}
internal static bool IsDangerousUrl(string s)
{
if (string.IsNullOrEmpty(s))
{
return false;
}
s = s.Trim();
int length = s.Length;
if (((((length > 4) ((s[0] == 'h') || (s[0] == 'H'))) ((s[1] == 't') || (s[1] == 'T'))) (((s[2] == 't') || (s[2] == 'T')) ((s[3] == 'p') || (s[3] == 'P')))) ((s[4] == ':') || (((length > 5) ((s[4] == 's') || (s[4] == 'S'))) (s[5] == ':'))))
{
return false;
}
if (s.IndexOf(':') == -1)
{
return false;
}
return true;
}
internal static bool IsValidJavascriptId(string id)
{
if (!string.IsNullOrEmpty(id))
{
return CodeGenerator.IsValidLanguageIndependentIdentifier(id);
}
return true;
}
}

  結果我們發現# ! / ? [a-zA-z] 這些情況驗證都是通不過的。
所以我們只需要重寫RequestValidator就可以了。
例如我們現在需要處理我們現在需要過濾QueryString中k=...的情況
復制代碼 代碼如下:

public class CustRequestValidator : RequestValidator
{
protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
validationFailureIndex = 0;
//我們現在需要過濾QueryString中k=...的情況
if (requestValidationSource == RequestValidationSource.QueryStringcollectionKey.Equals("k") value.StartsWith(""))
{
return true;
}
return base.IsValidRequestString(context, value, requestValidationSource, collectionKey, out validationFailureIndex);
}
}
  httpRuntime requestValidationType="MvcApp.CustRequestValidator"/>

個人在這里只是提供一個思想,歡迎大家拍磚!
您可能感興趣的文章:
  • Request.UrlReferrer中文亂碼解決方法
  • 如何用ajax來創建一個XMLHttpRequest對象
  • c# HttpWebRequest通過代理服務器抓取網頁內容應用介紹
  • Javascript Request獲取請求參數如何實現
  • Ajax通訊原理XMLHttpRequest
  • jquery ajax學習筆記2 使用XMLHttpRequest對象的responseXML
  • JavaScript下通過的XMLHttpRequest發送請求的代碼
  • javascript一個無懈可擊的實例化XMLHttpRequest的方法
  • javascript對XMLHttpRequest異步請求的面向對象封裝
  • jQuery ajax(復習)—Baidu ajax request分離版

標簽:信陽 常州 朔州 自貢 孝感 萊蕪 西雙版納 許昌

巨人網絡通訊聲明:本文標題《HttpRequest的QueryString屬性 的一點認識》,本文關鍵詞  HttpRequest,的,QueryString,屬性,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《HttpRequest的QueryString屬性 的一點認識》相關的同類信息!
  • 本頁收集關于HttpRequest的QueryString屬性 的一點認識的相關信息資訊供網民參考!
  • 推薦文章
    校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃
    日韩电影在线观看网站| 亚洲色图另类专区| 日本黄色一区二区| 久久国产精品99久久人人澡| 亚洲精品网站在线观看| 久久蜜桃一区二区| 成年人午夜久久久| 国产91精品一区二区麻豆亚洲| 免费人成精品欧美精品| 亚洲国产日韩在线一区模特| 国产精品久久久一区麻豆最新章节| 精品三级在线看| 欧美一级生活片| 91麻豆精品国产91| 欧美日韩在线三区| 欧美亚洲自拍偷拍| 日韩欧美电影在线| 欧美人与禽zozo性伦| 91啪九色porn原创视频在线观看| 国产盗摄一区二区| 国产大陆精品国产| 国产成人自拍网| 国产精品1区2区3区在线观看| 久久99精品久久久久久久久久久久| 日韩综合在线视频| 久久国产精品色婷婷| 美女网站色91| 国产精品一区二区无线| 国产精品资源在线| 国产传媒日韩欧美成人| 国产精品99久久久久久久女警| 精品一区二区综合| 国产91富婆露脸刺激对白| 免费欧美日韩国产三级电影| 日韩黄色免费电影| 麻豆精品新av中文字幕| 日韩 欧美一区二区三区| 美女爽到高潮91| 国产999精品久久久久久 | 亚洲mv在线观看| 亚洲成人av福利| 另类综合日韩欧美亚洲| 国产乱色国产精品免费视频| 国产sm精品调教视频网站| 国产一区二区久久| 色天使色偷偷av一区二区| 欧美电影免费观看高清完整版| 亚洲国产高清在线观看视频| 色老汉一区二区三区| 丰满白嫩尤物一区二区| 五月婷婷激情综合网| 国产成人啪免费观看软件 | 国产精品一区在线观看乱码 | 韩国女主播成人在线观看| 一本到不卡免费一区二区| 久久综合久久99| 美洲天堂一区二卡三卡四卡视频| 99久久99久久免费精品蜜臀| 亚洲精品在线免费播放| 美腿丝袜亚洲一区| 3d动漫精品啪啪一区二区竹菊| 一区二区久久久久久| av不卡一区二区三区| 精品国产乱码久久久久久免费| 天天色天天操综合| 欧美精品一二三区| 亚洲成人av福利| 欧美日韩亚洲综合在线| 亚洲综合激情网| 丁香一区二区三区| 中文字幕乱码日本亚洲一区二区| 国产一区二区按摩在线观看| 精品国产欧美一区二区| 日本美女一区二区三区| 欧美精品亚洲一区二区在线播放| 亚洲国产视频直播| 欧美亚日韩国产aⅴ精品中极品| 成人欧美一区二区三区白人| 一本到不卡免费一区二区| 国产精品国产三级国产aⅴ入口 | 日韩精品一区二区三区四区视频| 日本aⅴ免费视频一区二区三区| 欧美老人xxxx18| 日本va欧美va欧美va精品| 欧美一区二区三区在线| 狂野欧美性猛交blacked| 日韩欧美在线影院| 美女视频免费一区| 久久久精品影视| 不卡一二三区首页| 一区二区三区日韩欧美| 欧美美女喷水视频| 久久99精品国产麻豆婷婷| 日本一区二区三区久久久久久久久不| 国产成人激情av| 亚洲欧美偷拍三级| 欧美一区二区三区啪啪| 国产在线一区二区综合免费视频| 国产欧美综合在线| 在线免费观看成人短视频| 日韩黄色一级片| 欧美国产欧美综合| 欧美私人免费视频| 国产一区在线观看视频| 国产精品二三区| 91精品国产aⅴ一区二区| 国产精一区二区三区| 一区二区久久久久久| www一区二区| 日本韩国欧美三级| 国产一区二区久久| 亚洲v日本v欧美v久久精品| 2023国产精品| 91福利在线导航| 国产精品77777| 免费成人你懂的| 亚洲乱码中文字幕| 亚洲精品一区二区三区在线观看| 成人av免费在线播放| 美日韩一级片在线观看| 亚洲综合成人网| 2022国产精品视频| 欧美精品第1页| 色婷婷国产精品| 国产精品99精品久久免费| 日本午夜精品一区二区三区电影| 中文字幕一区二区三| 久久日韩粉嫩一区二区三区| 欧美三片在线视频观看| 成人黄页毛片网站| 黑人巨大精品欧美黑白配亚洲| 一区二区成人在线观看| 国产欧美日韩在线| 精品免费日韩av| 欧美日韩国产精选| 日本韩国欧美三级| 一本色道久久综合亚洲精品按摩| 国产福利91精品| 国产一区二区电影| 国产在线一区观看| 激情五月婷婷综合| 激情综合亚洲精品| 国产一区二区调教| 久久爱另类一区二区小说| 香蕉久久夜色精品国产使用方法 | 欧美久久婷婷综合色| 欧美影片第一页| 欧美性猛片xxxx免费看久爱| 99在线视频精品| 丰满岳乱妇一区二区三区| 国产在线看一区| 国产精品综合在线视频| 激情小说欧美图片| 精品在线视频一区| 国产一区二区三区在线观看免费 | 2023国产精华国产精品| 久久一区二区三区四区| 欧美刺激午夜性久久久久久久| 欧美又粗又大又爽| 91九色最新地址| 欧美三片在线视频观看| 欧美日韩一区久久| 欧美一区二区三区在| 337p日本欧洲亚洲大胆色噜噜| 日韩精品中文字幕在线一区| 国产在线精品一区二区三区不卡 | 91国产精品成人| 欧美一区二区成人6969| 久久综合久久综合亚洲| 亚洲老妇xxxxxx| 久久99精品国产.久久久久| 成人aaaa免费全部观看| 欧美精品v国产精品v日韩精品| 精品国产精品网麻豆系列| 最新欧美精品一区二区三区| 午夜久久久影院| 91麻豆高清视频| 久久午夜羞羞影院免费观看| 亚洲一区二区三区在线看| 成人小视频免费在线观看| 欧美日韩一区 二区 三区 久久精品| 欧美哺乳videos| 婷婷久久综合九色综合伊人色| 国产精品一区二区在线观看不卡| 欧美亚洲日本一区| 欧美国产日韩亚洲一区| 久久99最新地址| 日韩色视频在线观看| 日韩av网站在线观看| 欧美精品在线一区二区| 亚洲欧美国产三级| 色哦色哦哦色天天综合| 中文字幕亚洲成人| 欧美日韩视频专区在线播放| 亚洲少妇最新在线视频| 欧美在线免费视屏| 午夜精品久久久久久久99樱桃| 91精品国产综合久久婷婷香蕉| 亚洲激情六月丁香| 欧美精品日韩精品|