如何从网址获取ID [英] how to get id from url
问题描述
http://localhost:1163/NewProject/subject/test-subject-1.aspx
从这个网址我如何使用request.QuryString获取ID 1(在示例中).
http://localhost:1163/NewProject/subject/test-subject-1.aspx
from this url how can i get the id 1(in the example) using request.QuryString.
推荐答案
从这个网址我如何获取使用request.QuryString的ID 1(在示例中).
你不能.
查询字符串是紧随其后的页面之后的内容.
您的网址不使用查询字符串.
您可以改用Request.Url.AbsoluteUri
.
[VB]
from this url how can i get the id 1(in the example) using request.QuryString.
You can''t.
Query string is something that follows the page after ?
Your URL doesn''t use query string.
You can useRequest.Url.AbsoluteUri
instead.
[VB]
Dim s as String = System.IO.Path.GetFileName(Request.Url.AbsoluteUri).ToLower().Replace(".aspx", "")
Dim number as String = s.Substring(s.LastIndexOf("-") + 1)
[C#]
[C#]
string s = System.IO.Path.GetFileName(Request.Url.AbsoluteUri).ToLower().Replace(".aspx", "");
string number = s.Substring(s.LastIndexOf("-") + 1);
您可以稍后将其转换为整数.
如果您确实使用查询字符串,那么Request.QueryString["ID"]
就足够了.
You can convert it to integer later.
If you really use query string then Request.QueryString["ID"]
is enough.
您不能使用Request.QueryString
,因为您没有查询字符串.为了执行您想做的事情,示例URL需要看起来像这样:
http://localhost:1163/NewProject/subject/test-subject-1.aspx?ID=1
此时,您可以执行以下操作:
You can''t useRequest.QueryString
because you don''t have a query string. In order to do what is is that you appear to want to do, your example URL needs to look like this:
http://localhost:1163/NewProject/subject/test-subject-1.aspx?ID=1
At that point, you can do this:
int id;
Int32.TryParse(Request.QueryString["ID"], out id);
在不了解您的特定环境和要求的情况下,我无法获得比这更具体的信息,并且我假设您具有编程知识,以了解如何确保您的代码将处理有关以下方面的有效性的所有可能的意外情况:数据.
Without knowing more about your specific environment and requirements, I can''t get any more specific than that, and I''m assuming that you have the programming chops to know how to ensure that your code will handle all possible contingencies regarding validty of data.
hai,
如果要获取request.QuryString.你必须给QuryString.
这是前任:将为您提供帮助
hai,
if you want to get request.QuryString. you have to give QuryString.
here is the ex: will help you
//on navigavigation gilike this aspx?ID=1 here the id the value
http://localhost:1163/NewProject/subject/test-subject-1.aspx?ID=1
//when you want to get it
if(Request.QueryString["ID"] != null)
{
string id=Request.QueryString["Request"].ToString();
}
这篇关于如何从网址获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!