3

I don't know how to put the title but i will try to explain it the requirement here.

Normally user entered an URL in address bar in browser, for example www.example.com, then click a link and redirect to another page www.example.com/test.aspx. Alternatively, user also can just enter/type www.example.com/test.aspx from address bar if they know the full path.

So, i required to write a code where user can type an URL in address bar, for example www.example.com/test.aspx?usr="www.test.com". (note: with addition usr="www.test.com")
The "usr="www.test.com" after www.example.com/test.aspx? contain a value that stored in database.
So, when the user type www.example.com/test.aspx?usr="www.test.com" it will search the database for matching www.test.com and do some process if found.

How can i achieve this.

Lynx
  • 259
  • 1
  • 9
  • 26
  • It is not clear what you're asking here. Reading a querystring, connectong to a database, and executing some code are all far too broad topics to cover. To you have a specific programming question you wish to ask? – Jamiec Oct 23 '12 at 09:44
  • Million thanks for those who answer, all the answer is correct for my case. That what i am searching. Tried google but that guy understand just a simple/short question not a long explanation. – Lynx Oct 24 '12 at 04:16

3 Answers3

6

You have to use Request.QueryString to get value any param passed to the page. The result, stored in a page variable, can be used to retrieve the needed data.

string usr = Request.QueryString["usr"];
Emanuele Greco
  • 12,551
  • 7
  • 51
  • 70
2

If the value is being passed through in the query string (the part after the '?'), you can just check for it using the Request object.

C#

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

Note: You can also use string url = HttpContext.Current.Request.QueryString["usr"]; if you want to ensure that your value of usr is only from the query string and not a POST or COOKIE. See here for further info.

Community
  • 1
  • 1
Scott
  • 21,211
  • 8
  • 65
  • 72
2

You can get the values in url after ? from HttpContext using

string url = HttpContext.Current.Request["usr"];
Asif Mushtaq
  • 13,010
  • 3
  • 33
  • 42