简体   繁体   中英

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

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.

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.

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"]);

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM