如何使用C#读取从asp.net页面传递的参数?

时间:2020-12-26 02:20:23

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).

我是ASP.net的新手,如何读取从ASP.net页面传递的参数(http://website.com/index.aspx?id=12&nam=eee)。

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

任何小例子都会受到赞赏,这对我来说只是一件好事。

4 个解决方案

#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.

阅读MSDN上的Request.QueryString。您可能希望将id值转换为int。

#2


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

出于安全考虑,请小心XSS攻击。请使用此库:

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.

它们在Request.QueryString中可用。这是字符串键/值对的集合,也可以通过序数索引访问。

#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.

阅读MSDN上的Request.QueryString。您可能希望将id值转换为int。

#2


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

出于安全考虑,请小心XSS攻击。请使用此库:

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.

它们在Request.QueryString中可用。这是字符串键/值对的集合,也可以通过序数索引访问。