Please help me to get query string value from the URL.
请帮我从URL获取查询字符串值。
http://test.com/test.aspx#id=test
I tried to access with
我试图访问
Request.QueryString["id"]
Its getting null value.Please suggest how to access id from the url.
它获得null值。请建议如何从url访问id。
Thanks
5 个解决方案
#1
10
I agree with everyone that the #
should be a ?
, but just FYI:
我同意所有人的观点,#应该是?,但仅限于FYI:
Note it isn't actually possible get the anchor off the URL, for example:
请注意,实际上不可能从URL中获取锚点,例如:
http://test.com/test.aspx#id=test
The problem is that # specified an anchor in the page, so the browser sees:
问题是#在页面中指定了一个锚点,因此浏览器会看到:
http://test.com/test.aspx
And then looks in the page for
然后在页面中查找
<a id="test">Your anchor</a>
As this is client side you need to escape the # from the URL - you can't get it on the server because the browser's already stripped it off.
由于这是客户端,您需要从URL中转义# - 您无法在服务器上获取它,因为浏览器已将其剥离。
If you want the part after the # you have to copy it using Javascript before the request is sent to the server, and put the value in the querystring.
如果你想要#之后的部分,你必须在将请求发送到服务器之前使用Javascript复制它,并将值放在查询字符串中。
More info here c# get complete URL with "#"
更多信息在这里c#获取带有“#”的完整网址
#2
8
A query string starts with a question mark ?
not a hash #
.
查询字符串以问号开头?不是哈希#。
Try:
http://test.com/test.aspx?id=test
Using a hash, you're asking to jump to a named anchor within the document, not providing a query string
使用哈希,您要求跳转到文档中的命名锚点,而不是提供查询字符串
#3
6
Your URL is not valid.
您的网址无效。
http://test.com/test.aspx#id=test
refers to a bookmark named id=test
.
指的是名为id = test的书签。
You should use
你应该用
http://test.com/test.aspx?id=test
And then Request.QueryString["id"]
will work.
然后Request.QueryString [“id”]将起作用。
#4
4
If you would like to use it as hash tag you can use:
如果您想将它用作哈希标记,您可以使用:
string value = Request.Url.ToString().Split('#')[1];
with this code, you will have your hash tag value.
使用此代码,您将获得哈希标记值。
#5
2
Isnt it supposed to be?
不应该是吗?
http://test.com/test.aspx?id=test
#1
10
I agree with everyone that the #
should be a ?
, but just FYI:
我同意所有人的观点,#应该是?,但仅限于FYI:
Note it isn't actually possible get the anchor off the URL, for example:
请注意,实际上不可能从URL中获取锚点,例如:
http://test.com/test.aspx#id=test
The problem is that # specified an anchor in the page, so the browser sees:
问题是#在页面中指定了一个锚点,因此浏览器会看到:
http://test.com/test.aspx
And then looks in the page for
然后在页面中查找
<a id="test">Your anchor</a>
As this is client side you need to escape the # from the URL - you can't get it on the server because the browser's already stripped it off.
由于这是客户端,您需要从URL中转义# - 您无法在服务器上获取它,因为浏览器已将其剥离。
If you want the part after the # you have to copy it using Javascript before the request is sent to the server, and put the value in the querystring.
如果你想要#之后的部分,你必须在将请求发送到服务器之前使用Javascript复制它,并将值放在查询字符串中。
More info here c# get complete URL with "#"
更多信息在这里c#获取带有“#”的完整网址
#2
8
A query string starts with a question mark ?
not a hash #
.
查询字符串以问号开头?不是哈希#。
Try:
http://test.com/test.aspx?id=test
Using a hash, you're asking to jump to a named anchor within the document, not providing a query string
使用哈希,您要求跳转到文档中的命名锚点,而不是提供查询字符串
#3
6
Your URL is not valid.
您的网址无效。
http://test.com/test.aspx#id=test
refers to a bookmark named id=test
.
指的是名为id = test的书签。
You should use
你应该用
http://test.com/test.aspx?id=test
And then Request.QueryString["id"]
will work.
然后Request.QueryString [“id”]将起作用。
#4
4
If you would like to use it as hash tag you can use:
如果您想将它用作哈希标记,您可以使用:
string value = Request.Url.ToString().Split('#')[1];
with this code, you will have your hash tag value.
使用此代码,您将获得哈希标记值。
#5
2
Isnt it supposed to be?
不应该是吗?
http://test.com/test.aspx?id=test