{"id":504,"date":"2009-07-01T12:31:00","date_gmt":"2009-07-01T04:31:00","guid":{"rendered":""},"modified":"2013-11-17T13:14:27","modified_gmt":"2013-11-17T05:14:27","slug":"%e5%9c%a8asp-net%e4%b8%ad%e9%a1%b5%e9%9d%a2%e4%bc%a0%e5%80%bc%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/504.html","title":{"rendered":"\u5728ASP.NET\u4e2d\u9875\u9762\u4f20\u503c\u7684\u51e0\u79cd\u65b9\u5f0f"},"content":{"rendered":"<p>1\u3001\u8868\u5355\u63d0\u4ea4<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;form action= &quot;target.aspx&quot; method = &quot;post&quot; name = &quot;form1&quot;&gt;\r\n&lt;input name = &quot;param1&quot; value = &quot;1111&quot;\/&gt;\r\n&lt;input name = &quot;param2&quot; value = &quot;2222&quot;\/&gt; \r\n&lt;\/form&gt;\r\n....\r\nform1.submit();\r\n....\r\n<\/pre>\n<p>\u6b64\u79cd\u65b9\u5728ASP\u3002NET\u4e2d\u65e0\u6548\uff0c\u56e0\u4e3aASP\u3002NET\u7684\u8868\u5355\u603b\u662f\u63d0\u4ea4\u5230\u81ea\u8eab\u9875\u9762\uff0c\u5982\u679c\u8981\u63d0\u4ea4\u5230\u522b\u4e00\u9875\u9762\uff0c\u9700\u8981\u7279\u6b8a\u5904\u7406\u3002<\/p>\n<p>2\u3001\u94fe\u63a5\u5730\u5740\u4f20\u9001<br \/>\n\u63a5\u6536\u9875\u9762\uff1a string str = Request[&#8220;param1&#8221;]<\/p>\n<p>3\u3001Session\u5171\u4eab<br \/>\n\u53d1\u9001\u9875\u9762\uff1aSession(&#8220;param1&#8221;) = &#8220;1111&#8221;;<br \/>\n\u6309\u6536\u9875\u9762 string str = Session(&#8220;param1&#8221;).ToString(); <\/p>\n<p>4\u3001Application\u5171\u4eab<br \/>\n\u53d1\u9001\u9875\u9762\uff1a Application(&#8220;param1&#8221;) = &#8220;1111&#8221;;<br \/>\n\u6309\u6536\u9875\u9762\uff1a string str = Application(&#8220;param1&#8221;).ToString();<br \/>\n\u6b64\u79cd\u65b9\u6cd5\u4e0d\u5e38\u4f7f\u7528\uff0c\u56e0\u4e3aApplication\u5728\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u57df\u8303\u56f4\u5171\u4eab\uff0c\u6240\u6709\u7528\u6237\u53ef\u4ee5\u6539\u53d8\u53ca\u8bbe\u7f6e\u5176\u503c\uff0c\u6545\u53ea\u5e94\u7528\u8ba1\u6570\u5668\u7b49\u9700\u8981\u5168\u5c40\u53d8\u91cf\u7684\u5730\u65b9\u3002<\/p>\n<p>5\u3001Cookie<\/p>\n<p>6\u3001Response.Redirect()\u65b9\u5f0f<br \/>\nResponse.Redirect(&#8220;target.aspx?param1=1111?m2=2222&#8221;)<br \/>\n\u63a5\u6536\u9875\u9762\uff1a string str = Request[&#8220;param1&#8221;]<\/p>\n<p>7\u3001Server.Transfer()\u65b9\u5f0f\u3002<br \/>\nServer.Transfer(&#8220;target.aspx?param1=1111?m2=2222&#8221;)<br \/>\n\u63a5\u6536\u9875\u9762\uff1a string str = Request[&#8220;param1&#8221;]<br \/>\n\u4e8c\u3001\u5982\u679c\u5728\u4e24\u4e2a\u9875\u9762\u95f4\u9700\u8981\u5927\u91cf\u7684\u53c2\u6570\u8981\u4f20\u4f20\u9012\uff0c\u5982\u6570\u636e\u67e5\u8be2\u7b49\u9875\u9762\u65f6\uff0c\u75281 \uff0d 6\u7684\u65b9\u6cd5\u4f20\u503c\u53ca\u5176\u4e0d\u4fbf\uff0c\u800c\u7b2c 7 \u79cd\u65b9\u6cd5\u786e\u6709\u4e00\u72ec\u7279\u7684\u4f18\u52bf\uff01\u4f46\u4f7f\u7528\u8be5\u65b9\u6cd5\u65f6\u9700\u8981\u4e00\u5b9a\u7684\u8bbe\u7f6e\uff0c\u73b0\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u8be5\u65b9\u6cd5\u7684\u4f7f\u7528\u65b9\u5f0f\uff1a<br \/>\n\u4ee5\u67e5\u8be2\u6570\u636e\u9875\u9762\u4e3a\u4f8b\uff1a<br \/>\n\u5728\u67e5\u8be2\u9875\u9762\u4e2d\u8bbe\u7f6e\u5982\u4e0b\u516c\u6709\u5c5e\u6027(QueryPage.aspx)\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class QueryPage : System.Web.UI.Page\r\n{\r\nprotected System.Web.UI.WebControls.TextBox txtStaDate;\r\nprotected System.Web.UI.WebControls.TextBox txtEndDate;\r\n\r\n\/**\/\/\/\/ \r\n\/\/\/ \u5f00\u59cb\u65f6\u95f4\r\n\/\/\/ \r\npublic string StaDate\r\n{\r\nget{ return this.txtStaDate.Text;}\r\nset{this.txtStaDate.Text = value;}\r\n}\r\n\/**\/\/\/\/ \r\n\/\/\/ \u7ed3\u675f\u65f6\u95f4\r\n\/\/\/ \r\npublic string EndDate\r\n{\r\nget{ return this.txtEndDate.Text;}\r\nset{this.txtEndDate.Text = value;}\r\n}\r\n\r\nprivate void btnEnter_Click(object sender, System.EventArgs e)\r\n{\r\nServer.Transfer(&quot;ResultPage.aspx&quot;);\r\n}\r\n}\r\n<\/pre>\n<p>\u5728\u663e\u793a\u67e5\u8be2\u7ed3\u679c\u9875\u9762(ResultPage.aspx)\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class ResultPage : System.Web.UI.Page\r\n{\r\nprivate void Page_Load(object sender, System.EventArgs e)\r\n{\r\n\r\n\/\/\u8f6c\u6362\u4e00\u4e0b\u5373\u53ef\u83b7\u5f97\u524d\u4e00\u9875\u9762\u4e2d\u8f93\u5165\u7684\u6570\u636e\r\nQueryPage queryPage = ( QueryPage )Context.Handler;\r\n\r\nResponse.Write( &quot;StaDate\uff1a&quot; );\r\nResponse.Write( queryPage.StaDate );\r\nResponse.Write( &quot;\r\nEndDate\uff1a&quot; );\r\nResponse.Write( queryPage.EndDate );\r\n}\r\n}\r\n<\/pre>\n<p>\u4e09\u3001\u5982\u679c\u6709\u8bb8\u591a\u67e5\u8be2\u9875\u9762\u5171\u7528\u4e00\u4e2a\u7ed3\u679c\u9875\u9762\u7684\u8bbe\u7f6e\u65b9\u6cd5\uff1a<br \/>\n\u5728\u8fd9\u79cd\u65b9\u5f0f\u4e2d\u5173\u952e\u5728\u4e8e\u201c QueryPage queryPage = ( QueryPage )Context.Handler; \u201d\u7684\u8f6c\u6362\uff0c\u53ea\u6709\u8f6c\u6362\u4e0d\u4f9d\u8d56\u4e8e\u7279\u5b9a\u7684\u9875\u9762\u65f6\u5373\u53ef\u5b9e\u73b0\u3002<br \/>\n\u5982\u679c\u8ba9\u6240\u6709\u7684\u67e5\u8be2\u9875\u9762\u90fd\u7ee7\u627f\u4e00\u4e2a\u63a5\u53e3\uff0c\u5728\u8be5\u63a5\u53e3\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u7684\u552f\u4e00\u4f5c\u7528\u5c31\u662f\u8ba9\u7ed3\u679c\u9875\u9762\u83b7\u5f97\u6784\u5efa\u7ed3\u679c\u65f6\u6240\u9700\u7684\u53c2\u6570,\u5c31\u53ef\u5b9e\u73b0\u591a\u9875\u9762\u5171\u4eab\u4e00\u4e2a\u7ed3\u679c\u9875\u9762\u64cd\u4f5c\uff01<\/p>\n<p>1\u3001\u5148\u5b9a\u4e49\u4e00\u4e2a\u7c7b\uff0c\u7528\u8be5\u7c7b\u653e\u7f6e\u6240\u6709\u67e5\u8be2\u53c2\u6570\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/**\/\/\/\/ \r\n\/\/\/ \u7ed3\u679c\u9875\u9762\u4e2d\u8981\u7528\u5230\u7684\u503c\r\n\/\/\/ \r\npublic class QueryParams\r\n{\r\nprivate string staDate;\r\nprivate string endDate;\r\n\r\n\/**\/\/\/\/ \r\n\/\/\/ \u5f00\u59cb\u65f6\u95f4\r\n\/\/\/ \r\npublic string StaDate\r\n{\r\nget{ return this.staDate;}\r\nset{this.staDate = value;}\r\n}\r\n\/**\/\/\/\/ \r\n\/\/\/ \u7ed3\u675f\u65f6\u95f4\r\n\/\/\/ \r\npublic string EndDate\r\n{\r\nget{ return this.endDate;}\r\nset{this.endDate = value;}\r\n}\r\n}\r\n<\/pre>\n<p>2\u3001\u63a5\u53e3\u5b9a\u4e49\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/**\/\/\/\/ \r\n\/\/\/ \u5b9a\u4e49\u67e5\u8be2\u63a5\u53e3\u3002\r\n\/\/\/ \r\npublic interface IQueryParams\r\n{\r\n\/**\/\/\/\/ \r\n\/\/\/ \u53c2\u6570\r\n\/\/\/ \r\nQueryParams Parameters{get;}\r\n}\r\n<\/pre>\n<p>3\u3001\u67e5\u8be2\u9875\u9762\u7ee7\u627fIQueryParams\u63a5\u53e3(QueryPage.aspx)\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/**\/\/\/\/ \r\n\/\/\/\u67e5\u8be2\u9875\u9762\uff0c\u7ee7\u627f\u63a5\u53e3\r\n\/\/\/ \r\npublic class QueryPage : System.Web.UI.Page, IQueryParams\r\n{\r\nprotected System.Web.UI.WebControls.TextBox txtStaDate;\r\nprotected System.Web.UI.WebControls.TextBox txtEndDate;\r\n\r\nprivate QueryParams queryParams;\r\n\r\n\/**\/\/\/\/ \r\n\/\/\/ \u7ed3\u679c\u9875\u9762\u7528\u5230\u7684\u53c2\u6570\r\n\/\/\/ \r\npublic QueryParams Parameters\r\n{\r\nget\r\n{\r\nreturn queryParams;\r\n}\r\n}\r\n.\r\nprivate void btnEnter_Click(object sender, System.EventArgs e)\r\n{\r\n\/\/\u8d4b\u503c\r\nqueryParams = new QueryParams();\r\nqueryParams.StaDate = this.txtStaDate.Text;\r\nqueryParams.EndDate = this.txtEndDate.Text\r\n\r\nServer.Transfer(&quot;ResultPage.aspx&quot;);\r\n}\r\n}\r\n<\/pre>\n<p>4\u3001\u522b\u5916\u7684\u9875\u9762\u4e5f\u5982\u6b64\u8bbe\u7f6e<\/p>\n<p>5\u3001\u63a5\u6536\u9875\u9762(ResultPage.aspx)\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class ResultPage : System.Web.UI.Page\r\n{\r\nprivate void Page_Load(object sender, System.EventArgs e)\r\n{\r\n\r\nQueryParams queryParams = new QueryParams();\r\nIQueryParams queryInterface;\r\n\/\/\u5b9e\u73b0\u8be5\u63a5\u53e3\u7684\u9875\u9762\r\nif( Context.Handler is IQueryParams)\r\n{\r\nqueryInterface = ( IQueryParams )Context.Handler;\r\nqueryParams = queryInterface.Parameters;\r\n}\r\n\r\nResponse.Write( &quot;StaDate\uff1a&quot; );\r\nResponse.Write( queryParams.StaDate );\r\nResponse.Write( &quot;\r\nEndDate\uff1a&quot; );\r\nResponse.Write( queryParams.EndDate );\r\n}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u8868\u5355\u63d0\u4ea4 &lt;form action= &quot;target.aspx&quot; method  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=504"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/504\/revisions"}],"predecessor-version":[{"id":4624,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/504\/revisions\/4624"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}