如何从客户端输入的地址栏中获取值



我不知道如何放置标题,但我会尝试在此处解释要求。


通常,用户在浏览器的地址栏中输入一个URL,例如 www.example.com ,然后单击链接,然后重定向到另一个页面 www.example.com/test.aspx 另外,用户也可以输入/键入 www.example.com/test.aspx ,如果他们知道完整的路径。

因此,我需要编写一个代码,用户可以在地址栏中输入URL,例如 www.example.com/test.aspx?usr=" www.test.com" 。(注意:加法 usr =" www.test.com"
" usr =" www.test.com" www.example.com/test.aspx?包含一个存储在数据库中的值。

因此,当用户类型 www.example.com/test.aspx?usr =" www.test.com" 它将搜索数据库以搜索匹配的 www.test.com 如果找到了一些过程。

我该如何实现。

您必须使用request.querystring获取传递给页面的任何参数的值。存储在页面变量中的结果可用于检索所需的数据。

string usr = Request.QueryString["usr"];

您可以使用

从httpcontext获得 ?之后的url值
string url = HttpContext.Current.Request["usr"];

如果在查询字符串中通过该值('?'之后的零件),则可以使用请求对象进行检查。

c#

string url = HttpContext.Current.Request["usr"];
// Then perform your search based on the value in URL.

注意:如果要确保usr的值仅来自查询字符串而不是帖子或cookie,也可以使用string url = HttpContext.Current.Request.QueryString["usr"];。请参阅此处以获取更多信息。

最新更新