Parameter parsing and URL simplification

B

Beginner

Hello,

I'm designing a webpage about trees and I have two questions.

I currently have a /Default.aspx webpage; it is a content page of a master
page (Main.master) with the main menu and the logo. When you select one
category from the menu (say, deciduous trees), I query a database and
present the results to the user. So far so good.

The problem comes when the user clicks on a result (say, cork oak). My
initial though was to link to a page named /Trees.aspx?ID=1234, where "1234"
is the identifier of the cork oak, but I don't know how to do this. I
suppose that I need to parse the parameter from the URL, then get the
content about cork oaks and present it to the user, but I need your help. If
you could sketch the code of my /Trees.aspx page...

My second question is "Is it possible to have a more user-friendly URL such
as www.mysite.com/Articles/CorkOak instead of
www.mysite.com/Trees.aspx?ID=1234"? If so, how to do this? I though about
creating the directory layout /Articles/CorkOak and then place a simple
Default.aspx in there, but maybe there are better, more professional
options.

Thanks,

P.S: I'm using ASP.net 2.0
 
S

Stan

Hello,

I'm designing a webpage about trees and I have two questions.

I currently have a /Default.aspx webpage; it is a content page of a master
page (Main.master) with the main menu and the logo. When you select one
category from the menu (say, deciduous trees), I query a database and
present the results to the user. So far so good.

The problem comes when the user clicks on a result (say, cork oak). My
initial though was to link to a page named /Trees.aspx?ID=1234, where "1234"
is the identifier of the cork oak, but I don't know how to do this. I
suppose that I need to parse the parameter from the URL, then get the
content about cork oaks and present it to the user, but I need your help. If
you could sketch the code of my /Trees.aspx page...

My second question is "Is it possible to have a more user-friendly URL such
aswww.mysite.com/Articles/CorkOakinstead ofwww.mysite.com/Trees.aspx?ID=1234"? If so, how to do this? I though about
creating the directory layout /Articles/CorkOak and then place a simple
Default.aspx in there, but maybe there are better, more professional
options.

Thanks,

P.S: I'm using ASP.net 2.0

Hi

To retrieve the parameter value from a query string you could do this
(in C#):

int ID = -1;
if(Request.QueryString["ID"] != null) ID = int.parse
(Request.QueryString["ID"]);

(remaining code would depend on whether ID is -1 or not)

I can't answer your second question without a bit more explanation. I
presume you understand that a URL of the form you propose would mean
that the page would be dedicated to one particular tree and so the ID
used to retrieve the data would be hard coded as a constant within the
page?
 
A

André Freitas

About the second question I think he wants a friendly url.

If so: http://www.4guysfromrolla.com/articles/011007-1.aspx

Regards,
André.

Stan said:
Hello,

I'm designing a webpage about trees and I have two questions.

I currently have a /Default.aspx webpage; it is a content page of a
master
page (Main.master) with the main menu and the logo. When you select one
category from the menu (say, deciduous trees), I query a database and
present the results to the user. So far so good.

The problem comes when the user clicks on a result (say, cork oak). My
initial though was to link to a page named /Trees.aspx?ID=1234, where
"1234"
is the identifier of the cork oak, but I don't know how to do this. I
suppose that I need to parse the parameter from the URL, then get the
content about cork oaks and present it to the user, but I need your help.
If
you could sketch the code of my /Trees.aspx page...

My second question is "Is it possible to have a more user-friendly URL
such
aswww.mysite.com/Articles/CorkOakinstead
ofwww.mysite.com/Trees.aspx?ID=1234"? If so, how to do this? I though
about
creating the directory layout /Articles/CorkOak and then place a simple
Default.aspx in there, but maybe there are better, more professional
options.

Thanks,

P.S: I'm using ASP.net 2.0

Hi

To retrieve the parameter value from a query string you could do this
(in C#):

int ID = -1;
if(Request.QueryString["ID"] != null) ID = int.parse
(Request.QueryString["ID"]);

(remaining code would depend on whether ID is -1 or not)

I can't answer your second question without a bit more explanation. I
presume you understand that a URL of the form you propose would mean
that the page would be dedicated to one particular tree and so the ID
used to retrieve the data would be hard coded as a constant within the
page?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top