问题描述
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.
推荐答案
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.
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.
//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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!