ASP.net中的查询字符串 [英] query string in ASP.net
问题描述
您好,
我需要从URL读取查询字符串。
例如。 www.xyz.com/what-is-your-name
如何从URL读取此类查询字符串?
我知道我可以使用www.xyz.com/handlepage.aspx?s=what-is-your-name,但我不想在这里指定查询字符串处理程序。
Prathamesh
Hello,
I need to read a query string from a URL.
eg. www.xyz.com/what-is-your-name
How can I read this type of query string from URL?
I know I can user www.xyz.com/handlepage.aspx?s=what-is-your-name, but I don't want to specify query string handler here.
Prathamesh
推荐答案
您可以使用UrlData对象从Url获取数据,例如,如果URL为您将阅读该名称的页面如http://www.example.com/page/MyNameHere
获取MyNameHere的代码将是这样的,< br $> b $ b
You can use UrlData objects to get the data from the Url, for example if the URL to the page where you would read the name is like http://www.example.com/page/MyNameHere
The code to get the MyNameHere would be like this,
var name = UrlData[0]; // first item in the Url,
您可以在URL中指定更多这些对象,以从URL中删除QueryStrings。阅读Mike的发布 [ ^ ]这些网址信息。
第二种方法可以是,在'/'处拆分URL,然后从数组中获取最后一个字符串。这将有页面和QueryString,用空字符串替换所有已知数据。剩余将包含名称变量。
还在问,为什么你不想再使用它?
You can specify many more these objects in the URL, to remove the QueryStrings from the URL. Read Mike's post[^] for these URL informations.
Second method of this can be, to split the URL at the '/' and after that, get the last string from array. That will have the page and the QueryString, replace all of the known data with an empty string. Remaining would contain the name variable.
Still asking, why you don't want to use it anyways?
这里的完整描述..
http://www.dotnetperls.com/querystring [ ^ ]
Full Description here..
http://www.dotnetperls.com/querystring[^]
这篇关于ASP.net中的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!