Asp.NET/VB.NET: Getting path from URL / URI?

Let's say I have a project that I am deploying to

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 "path1" or "path2" folder? Can I get this directly or do I need to split () somehow into Request.Url.AbsolutePath or ...?

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

Thanks for any help!

0


a source to share


3 answers


If you want to code this logic directly in the page, then yes, I would go with split () to Request.Url.AbsolutePath.



However, I would consider storing this type in the AppSettings section of the web.config file. Thus, if you decide to change the color in path2, you just need to edit the web.config file for path2. If you need to add a new path, just expand it and edit the web.config file accordingly.

+5


a source


Yes, use it Request.Url.AbsolutePath

.

I do this to create Breadcrumbs using Split to split the url and then in your case I suggest using the Switch statement to change the color depending on the case of the Switch statement



Here is a great article on ASP paths.

+3


a source


Check out the MSDN docs at System.IO.Path

. It contains a number of useful functions for working with path names. You can get GetDirectoryName()

either GetFullPath()

or GetFileName()

or GetFileNameWithoutExtension()

.

+1


a source







All Articles