如何使用Request.QueryString从url获取第二个字符串 [英] how to obtain second string from url with using Request.QueryString

查看:118
本文介绍了如何使用Request.QueryString从url获取第二个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个与 Request.QueryString有关的问题:

我从网址中获取具有以下格式的类别名称(我将URL名称替换为codeproject.com,没有广告).

codeproject.com/default.aspx?category = asp.net

以传入的URL类别名称为"asp.net"为例.我在代码站点后面查询SQL.

我的问题是我是否要从传入的URL查询2个字符串?我该怎么办.

我的意思是:
-在codeproject.com/default.aspx处添加第二个类别名称的位置?category = asp.net
-如何在代码站点使用Request.QueryString处理第二个category2名称.我使用以下代码处理类别字符串:

Hi,

I have a question related to Request.QueryString:

I obtain a category name from URL with following format (i replaced URL name with codeproject.com for no advertising).

codeproject.com/default.aspx?category =asp.net

According to the incoming URL category name "asp.net" for example. I query SQL behind the code site.

My question is if i want to query 2 string from incoming URL; how can i do.

I mean:
- where to add second category name at codeproject.com/default.aspx?category =asp.net
- how to handle second category2 name with Request.QueryString at code site. I handle category string with following code:

string catagory1="empty";
if(Request.QueryString["category"] !=null)
  {
     catagory1=Request.QueryString["catagory"].ToString();

  }



亲切的问候,



Kind Regards,

推荐答案

要将多个参数放入查询字符串,请使用&分开它们:

例如

To put multiple parameters into a query string, use & to separate them:

For example

example.com/default.asps?animal=tiger&fruit=apple



要提取它们,请使用



To extract them, use

string myAnimal = Request.QueryString("animal")
string myFruit = Request.QueryString("fruit")


实际上,您可以通过两种方式做到这一点.

1.您可以使用许多变量构建链接,例如:
www.whatever.com/default.aspx? category1 = A& category2 = B& category3 = C

2.您可以在一个类别名称中编写您的个人逻辑:
www.whatever.com/default.aspx? category = A | B | C
然后,当您获得类别值时,只需对其进行解析即可.

希望对您有所帮助.
Actually here are two ways you can do that.

1. You can build a link with many variables like:
www.whatever.com/default.aspx?category1=A&category2=B&category3=C and so on

2. You can program your personal logic in one category name:
www.whatever.com/default.aspx?category=A|B|C
and after when you get a category value just parse it.

I hope it helps.


这篇关于如何使用Request.QueryString从url获取第二个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆