How to read parameter passed from asp.net page, using C#?

不想你离开。 提交于 2019-12-20 01:10:41

问题


I'm new to ASP.net, how can I read parameters passed from ASP.net page (http://website.com/index.aspx?id=12&nam=eee).

Any small example will be appreciated, just something for me to start from.


回答1:


Using your sample URL:

string id = Request.QueryString["id"];

string nam = Request.QueryString["nam"];

Read about Request.QueryString on MSDN. You probably want to convert the id value to an int.




回答2:


For security reasons, be careful with XSS attacks. Please use this library:

http://msdn.microsoft.com/en-us/library/aa973813.aspx

Example:

String Name = AntiXss.HtmlEncode(Request.QueryString["Name"]);



回答3:


string st1=Request.QueryString["t1"].ToString();
string st1=Request.QueryString["t1"].ToString();
int a=Convert.ToInt32(st1)+Convert.ToInt32(st2);
Response.Write(a);



回答4:


They are available in Request.QueryString. This is a collection of string key/value pairs, that can also be accessed by ordinal index.



来源:https://stackoverflow.com/questions/1078171/how-to-read-parameter-passed-from-asp-net-page-using-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!