Print Page | Close Window

Reference to the site root

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=897
Printed Date: 28 March 2026 at 9:01am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Reference to the site root
Posted By: sardawg
Subject: Reference to the site root
Date Posted: 10 March 2003 at 2:10pm

I was just beginning to get a handle on ASP and now I have to drink the .NET through a firehose.  Oh well...

In a piece of code just like this one (so ignore any parts not directly relevant to the question): 

       objMyUserControl = CType(LoadControl
("UserControls/SelectArea.ascx"), SelectArea)
        AddHandler objMyUserControl.MyEvent, AddressOf ucSelectArea

I had to point to the root of the site. Remembering something from ASP, I inserted "../" just on front of the "UserControls/DSelectArea.ascx", making it:

"../UserControls/DSelectArea.ascx" which solved the problem.

In a later code example in the Wrox Press book I am using for a tutorial, they used "Request.ApplicationPath & Path.AltDirectorySeparatorChar & "UserControls/DSelectArea.ascx" to also solve the problem.

My question is, is there a reason like security or something why you should use all the code instead of 3 characters?

And/or, couldn't you put a variable in global.asax named "root" and set it equal to "Request.ApplicationPath & Path.AltDirectorySeparatorChar &" so when you needed a reference you could use "root/UserControls/DSelectArea.ascx" to get there?



-------------
V1...Vr...V2



Replies:
Posted By: MorningZ
Date Posted: 11 March 2003 at 7:07am
Originally posted by sardawg sardawg wrote:

My question is, is there a reason like security or something why you should use all the code instead of 3 characters?

maybe since it was a book to teach, they are trying to expose as much as the stuff available

Originally posted by sardawg sardawg wrote:

is there a reason like security or something why you should use all the code instead of 3 characters?

well, security isn't an issue, but what if you moved this file one more folder deeper? yup, your code with "../" (which says: go up one folder, then into the UserControls directory) would no longer function, since now you'd have to go up two levels (ie: "../../")

Originally posted by sardawg sardawg wrote:

And/or, couldn't you put a variable in global.asax named "root" and set it equal to "Request.ApplicationPath & Path.AltDirectorySeparatorChar &" so when you needed a reference you could use "root/UserControls/DSelectArea.ascx" to get there?

you could do that (of course your syntax would have to be: root & "UserControls/De....blahb lah"), but of course you could just say:
objMyUserControl = CType(LoadControl
("/UserControls/SelectArea.ascx"), SelectArea)

which'll know where to go no matter where you are in the application






-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net