4 Replies - 620 Views - Last Post: 16 August 2010 - 04:25 PM Rate Topic: -----

#1 Guest_eTech1*


Reputation:

Saving directory in seperate file (VB)

Posted 11 August 2010 - 08:16 AM

I would like to save my root directory string in a variable so that if the URL of my site ever changes I'll just have to change that variable and all links will work still. I've tried it in a usercontrol but since it's not in the page load no pages that bring that usercontrol in can see the variable.

IE.
Dim root1 as String = "http://www.mysite.com/"

and
<img src="<% response.write(root1) %>images/img1.png" />


How do most people do this? Is there a function for finding the root directory that I could use instead? Thanks for any help.

Is This A Good Question/Topic? 0

Replies To: Saving directory in seperate file (VB)

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Saving directory in seperate file (VB)

Posted 11 August 2010 - 08:53 AM

I would probably put it in the web.config file. Then, everytime you need it, read it from the web.config file. When you need to change it, simply change the web.config and you don't even have to do a republish of your site.

http://www.4guysfrom...s/053102-1.aspx
Was This Post Helpful? 1
  • +
  • -

#3 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Saving directory in seperate file (VB)

Posted 16 August 2010 - 01:18 PM

Why not just use Request.Url.AbsolutePath?

-Frinny

This post has been edited by Frinavale: 16 August 2010 - 01:18 PM

Was This Post Helpful? 1
  • +
  • -

#4 Guest_eTech1*


Reputation:

Re: Saving directory in seperate file (VB)

Posted 16 August 2010 - 02:43 PM

will that always just give me the http:// and domain name? I just didn't know if it would also include any directories so I didn't use it. Ill test for myself and just use that then when I get a chance. Thanks.
Was This Post Helpful? 0

#5 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Saving directory in seperate file (VB)

Posted 16 August 2010 - 04:25 PM

AbsolutePath will only return /images/img1.png from the URL.

If you only want the protocal (scheme) and the domain (host), then you need to access it from two separate properties of the Request object. These are Request.Url.Host and Request.Url.Scheme. Then it's just a matter of concatenating the two values together.

However, I would highly recommend that you DO NOT use absolute URL's in your website. For the very reason you originally stated.

Rather than hard-coding the URL, use a Project Path symbol to specify a relative URL to the directory you are in.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1