{"id":294092,"date":"2022-06-09T16:06:27","date_gmt":"2022-06-09T08:06:27","guid":{"rendered":"https:\/\/www.idc.net\/help\/294092\/"},"modified":"2022-06-09T16:06:27","modified_gmt":"2022-06-09T08:06:27","slug":"%e7%bd%91%e7%ab%99%e5%ae%89%e5%85%a8%ef%bc%9a%e6%95%b4%e7%ab%99%e5%a6%82%e4%bd%95%e9%98%b2%e6%ad%a2sql%e6%b3%a8%e5%85%a5%e6%96%b9%e5%bc%8f%e5%85%a5%e4%be%b5","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/294092\/","title":{"rendered":"\u7f51\u7ad9\u5b89\u5168\uff1a\u6574\u7ad9\u5982\u4f55\u9632\u6b62SQL\u6ce8\u5165\u65b9\u5f0f\u5165\u4fb5"},"content":{"rendered":"<p>\u9632\u6b62SQL\u6ce8\u5165\uff0c\u901a\u5e38\u4e00\u4e2a\u4e00\u4e2a\u6587\u4ef6\u4fee\u6539\u4e0d\u4ec5\u9ebb\u70e6\u800c\u4e14\u8fd8\u6709\u6f0f\u6389\u7684\u5371\u9669\uff0c\u4e0b\u9762\u6211\u8bf4\u4e00\u4e0b\u5982\u4f55\u4ece\u6574\u4e2a\u7cfb\u7edf\u9632\u6b62\u6ce8\u5165\u3002 <\/p>\n<p>\u505a\u5230\u4ee5\u4e0b\u4e09\u6b65\uff0c\u76f8\u4fe1\u4f60\u7684\u7a0b\u5e8f\u5c31\u4f1a\u6bd4\u8f83\u5b89\u5168\u4e86\uff0c\u800c\u4e14\u5bf9\u6574\u4e2a\u7f51\u7ad9\u7684\u7ef4\u62a4\u4e5f\u5c06\u53d8\u7684\u7b80\u5355\u3002 <\/p>\n<p><strong>\u4e00\u3001\u6570\u636e\u9a8c\u8bc1\u7c7b <\/strong><\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"400\" border=\"1\">\n<tbody>\n<tr>\n<td>\n<p><span>parameterCheck.cs<span>&nbsp;  <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp; <\/span><\/span><\/p>\n<p><span>public class parameterCheck{ <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; public static bool isEmail(string emailString){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return System.Text.RegularExpressions.Regex.IsMatch(emailString, \"['\\\\w_-]+(\\\\. <\/span><\/span><\/p>\n<p><span>['\\\\w_-]+)*@['\\\\w_-]+(\\\\.['\\\\w_-]+)*\\\\.[a-zA-Z]{2,4}\"); <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; public static bool isInt(string intString){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return System.Text.RegularExpressions.Regex.IsMatch(intString ,\"^(\\\\d{5}-\\\\d{4})| <\/span><\/span><\/p>\n<p><span>(\\\\d{5})$\"); <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; public static bool isUSZip(string zipString){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return System.Text.RegularExpressions.Regex.IsMatch(zipString ,\"^-[0-9]+$|^[0-9] <\/span><\/span><\/p>\n<p><span>+$\"); <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span>}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u4e8c\u3001Web.config <\/strong><\/p>\n<p>\u5728\u4f60\u7684Web.config\u6587\u4ef6\u4e2d\uff0c\u5728\u4e0b\u9762\u589e\u52a0\u4e00\u4e2a\u6807\u7b7e\uff0c\u5982\u4e0b\uff1a <\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"400\" border=\"1\">\n<tbody>\n<tr>\n<td><span><span> <\/p>\n<p><span>   <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;  <span>USzip\" \/&gt; <\/span> <\/span><\/span><\/p>\n<p><span><\/span><\/span><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4e2dkey\u662f\u540e\u9762\u7684\u503c\u4e3a\u201cOrderId-int32\u201d\u7b49\uff0c\u5176\u4e2d\u201c-\u201d\u524d\u9762\u8868\u793a\u53c2\u6570\u7684\u540d\u79f0\u6bd4\u5982\uff1aOrderId\uff0c\u540e\u9762\u7684int32\u8868\u793a\u6570\u636e\u7c7b\u578b\u3002 <\/p>\n<p><strong>\u4e09\u3001Global.asax <\/strong><\/p>\n<p>\u5728Global.asax\u4e2d\u589e\u52a0\u4e0b\u9762\u4e00\u6bb5\uff1a <\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"400\" border=\"1\">\n<tbody>\n<tr>\n<td>\n<p><span>protected void Application_BeginRequest(Object sender, EventArgs e){ <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; String[] safeParameters = System.Configuration.ConfigurationSettings.AppSettings <\/span><\/span><\/p>\n<p><span>[\"safeParameters\"].ToString().Split(','); <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; for(int i= 0 ;i &lt; safeParameters.Length; i++){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span>&nbsp;&nbsp;String parameterName = safeParameters[i].Split('-')[0]; <\/span><\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String parameterType = safeParameters[i].Split('-')[1]; <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isValidParameter(parameterName, parameterType); <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span>}<span>&nbsp; <\/span><\/span><\/p>\n<p><span>  &nbsp; <\/span><\/p>\n<p><span>public void isValidParameter(string parameterName, string parameterType){ <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; string parameterValue = Request.QueryString[parameterName]; <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; if(parameterValue == null) return; <\/span><\/span><\/p>\n<p><span>  &nbsp; <\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; if(parameterType.Equals(\"int32\")){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!parameterCheck.isInt(parameterValue)) Response.Redirect(\"parameterError.aspx\"); <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; else if (parameterType.Equals(\"double\")){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!parameterCheck.isDouble(parameterValue)) Response.Redirect(\"parameterError.aspx\"); <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; else if (parameterType.Equals(\"USzip\")){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!parameterCheck.isUSZip(parameterValue)) Response.Redirect(\"parameterError.aspx\"); <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; else if (parameterType.Equals(\"email\")){ <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!parameterCheck.isEmail(parameterValue)) Response.Redirect(\"parameterError.aspx\"); <\/span><\/span><\/p>\n<p><span><span>&nbsp;&nbsp;&nbsp; } <\/span><\/span><\/p>\n<p><span>}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u540e\u9700\u8981\u4fee\u6539\u7684\u65f6\u5019\u6211\u4eec\u53ea\u9700\u8981\u4fee\u6539\u4ee5\u4e0a\u4e09\u4e2a\u6587\u4ef6\uff0c\u5bf9\u6574\u4e2a\u7cfb\u7edf\u7684\u7ef4\u62a4\u5c06\u4f1a\u5927\u5927\u63d0\u9ad8\u6548\u7387\uff0c\u5f53\u7136\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u589e\u52a0\u5176\u5b83\u7684\u53d8\u91cf\u53c2\u6570\u548c\u6570\u636e\u7c7b\u578b\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9632\u6b62SQL\u6ce8\u5165\uff0c\u901a\u5e38\u4e00\u4e2a\u4e00\u4e2a\u6587\u4ef6\u4fee\u6539\u4e0d\u4ec5\u9ebb\u70e6\u800c\u4e14\u8fd8\u6709\u6f0f\u6389\u7684\u5371\u9669\uff0c\u4e0b\u9762\u6211\u8bf4\u4e00\u4e0b\u5982\u4f55\u4ece\u6574\u4e2a\u7cfb\u7edf\u9632\u6b62\u6ce8\u5165\u3002 \u505a\u5230\u4ee5\u4e0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202645],"tags":[],"class_list":["post-294092","post","type-post","status-publish","format-standard","hentry","category-202645"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/294092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=294092"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/294092\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=294092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=294092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=294092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}