0

Possible Duplicate:
How to read parameter passed from asp.net page, using C#?

I want to display profile contents on a ASP.NET web page based on the user id which is displayed at the end of a the URL, as in a facebook page.

I want to be able to derive the id from the URL just so I can search the database to match the Id.

If someone could help me derive the Id which is the last bit of the URL, I could convert that to a string and do the rest. Help on this is much appreciated.

Thank You

Community
  • 1
  • 1
Sinnerv
  • 263
  • 2
  • 6
  • 17

3 Answers3

1

This will depend on how you're programming and the structure of your URL.

Example; If the URL is something similar to http://mydomain.com/page.aspx?id=1 you can read the querystring by doing the following.

strID = Request.QueryString("ID");

In this instance the value of strID would be 1.

Are you using URL rewrite modules or simple Web Forms?

A. Agius
  • 1,211
  • 1
  • 14
  • 28
0

If you want to retrieve the name of the current page try:

Path.GetFileName(Request.Url.AbsolutePath);
n00b
  • 4,341
  • 5
  • 31
  • 57
0

My addition to the already solution:

 string url = HttpContext.Current.Request.Url.AbsoluteUri;

This code will give you the URL but storing UserId and sensitive data in url is not good practice. My Advice will be to use Encoding techniques with query string.

Usman Khalid
  • 3,032
  • 9
  • 41
  • 66