慎用Request.Params獲取參數值


今天一通道技術反映我們提交過去的url太長了,形如:

引用內容
http://service.5k3g.com/r.aspx?i=8986272,/ay/bajie10669611.ashx


在日志中找了相應的記錄,日志如下:

引用內容
http://219.140.177.243/ay/bajie10669611.ashx?pid=5&phone=13182000000&name=%e5%a8%83%e5%a8%83&url=http%3a%2f%2fservice.5k3g.com%2fr.aspx%3fi%3d8986272


並沒有多提交內容,最后發現原因是對方使用HttpContext.Current.Request.Params獲取參數值。我們先來看一個例子:

Response.Write(HttpContext.Current.Request.Params["url"]);
Response.Write(HttpContext.Current.Request["url"]);


1).http://localhost:1043/net/Send.aspx不帶參數時結果:

/net/Send.aspx //說明:Request.ServerVariables["url"]
/net/Send.aspx //說明:Request.ServerVariables["url"]

2).http://localhost:1043/net/Send.aspx?url=http://www.mzwu.com/帶參數時結果:

http://www.mzwu.com/,/net/Send.aspx //說明:Request.QueryString["url"],Request.ServerVariables["url"]
http://www.mzwu.com/ //說明:Request.QueryString["url"]

現在非常清楚了,我們來查看下官方兩個方法的說明吧:

HttpContext.Current.Request.Params是獲取 System.Web.HttpRequest.QueryString、System.Web.HttpRequest.Form、System.Web.HttpRequest.ServerVariables 和 System.Web.HttpRequest.Cookies 項的組合集合;
HttpContext.Current.Request是從System.Web.HttpRequest.Cookies、System.Web.HttpRequest.QueryString、System.Web.HttpRequest.Form 和 System.Web.HttpRequest.ServerVariables 集合中獲取指定的對象。

所以上邊的問題只需將HttpContext.Current.Request.Params改為HttpContext.Current.Request即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM