What is the common practice as far as URL page referencing in your code?

A

Amelyan

I am struggling here trying to determine what is a good programming practice
as far as referencing your URLs.

When you use Response.Redirect, do you use

1) Hard-coded string -- Response.Redirect("MyPage.aspx");
2) Constants -- Response.Redirect(STRMyPage); // where input parameter
is -> const string STRMyPage = "MyPage.aspx";
3) Something entirely differnent?

If you use constants do you keep them in one class as static public members,
e.g. MyUrlConstants.cs, then MyUrlConstans.STRMyPage.

Thanks,
Amelyan
 
R

Robbe Morris [C# MVP]

Typically, you wouldn't be changing the page filename (especially if you
want it indexed by the search engines). So why bother creating constants?
The page filename wouldn't change so it is, in affect, a constant already.
 
K

Karl Seguin

I can't disagree more. While you might not change filenames every day, I
think we've all lived through one exercise or another (redevelopment,
application merge, application split, ...) which has required this type of
work. It takes such little effor to build a flexible navigation model, I'm
not sure why you'd ever hard-code values. ASP.Net 2.0's built-in navigation
features should be proof positive that this is an important feature.

As such, what I would suggest would be to follow the SiteUrls example from
the CommuityServer project. Basically, you have a class which parses an xml
file..and exposes the results..There specific implementation is likely a
little more complicated than necessary, but I'd certainly go about something
similar.

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
C

clintonG

Karl's rationale is correct but he does not suggest an implementation
methodology. The easiest implementation will get the name of the page from
the server variables collection and using that value to populate a local
variable which is passed through the parameter of the redirect method of the
response object.

There is also much to be said about when to use the server.transfer method
instead of the response.redirect but I leave that for further study.

Finally, conforming with canonical form would require writing the variable
name as strMyPage rather than STRMyPage but I suggest it would clarify the
code to simplify and use strPageName when using this particular form of
notation.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 
A

Amelyan

Rob Morris mentioned "you wouldn't be changing the page filename especially
if you want it indexed by the search engines." I think this is a very
strong point. Does anyone disagree with that?
 
K

Karl Seguin

Sometimes you have to change the path. Sometimes you don't care about
search engines, or you control it (ie, on intranets for example). The point
is, sometimes you have to change it..so you change it! You might use
Redirects to keep existing search results happy...or url rewriting...

That isn't to say you should avoid it unless required to, I think what
Clinton and I think is that sometimes you don't have a choice and building
the flexibility upfront has a little cost for a huge gain.

Karl

P.S. - I did make a suggestions of sorts..that was to emualte what
CommunityServer did with XML files and SiteUrls...granted I could have been
more descriptive...
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top