views:

1514

answers:

3

Hello,

Say I have a project that I am deploying at

www.foo.com/path1/default.aspx

and

www.foo.com/path2/default.aspx

What would be the most reliable way to know if I was in the folder "path1", or "path2"? Can I grab that directly, or do I need to split() somehow on the Request.Url.AbsolutePath, or... ?

I just want to change colors, etc. based on which folder the user is in.

Thanks for any assistance!

+2  A: 

If you want to code that logic directly into the page, then yeah, I'd go with split() on Request.Url.AbsolutePath.

That said, I'd consider storing this kind of setting in the AppSettings section of web.config. That way if you decide to change the color in path2, you just need to edit the web.config for path2. If you need to add a new path, just deploy there and edit the web.config as appropriate.

Yuliy
A: 

yeah use Request.Url.AbsolutePath.

i do it to create Breadcrumbs, using Split to split the URL, then in your case i suggest to use Switch statement to change color based on the case of the Switch statement

here is a great article about Paths in ASP. http://www.west-wind.com/weblog/posts/269.aspx

A: 

Check out the MSDN docs on System.IO.Path. It contains a number of useful functions for dealing with path names. You can get GetDirectoryName() or GetFullPath() or GetFileName() or GetFileNameWithoutExtension().

icemanind