What's with "~/" and NOT "~/" ?

In trying to deplay test projects to my provider (GoDaddy) I'm finding a consistent barfness with the form of reference that I read as "in this directory, this file"  or "~/filename.filetype". I am having to consistently strip the "~/" to make it work.

Is there a way to strip off this type of reference through a preference? In the past, I've been led to believe that "filename.filetype" when in the same directory was just FINE as that -- no need for this "~/".

Hints, direction, etc. welcomed and appreciated in advance ... mahalos ... :)  KevInKauai 

0
KevInKauai
6/1/2007 11:01:39 PM
asp.net.web-dev-2005-express 3977 articles. 0 followers. Follow

9 Replies
1145 Views

Similar Articles

[PageSpeed] 16

This ~ is a great help in asp.net but will only work with controls running on the server. i.e. I can have an ordinary anchor <a href="~/somefile.aspx">here</a> and it won't work but make it a server control and I can use it. <a href="~/somefile.aspx" runat="server">here</a>. The usefullness of this ~ is that you can reference files in folders from anywhere in your application. e.g. if a user is viewing a page say here http://mysite.com/folder1/hello.aspx and you want to place a link on this page pointing to http://mysite.com/folder2/somepage.aspx then you can just use ~/folder2/somepage.aspx. This is handy because very often you can't be certain where you will be relative to the page you want to link to. The ~ makes it simple for you. If you have a masterpage in a templates folder, a usercontrol on it which is in a controls folder and a page in a sub folder using the masterpage then you may be unsure of where links will actually point if you place them on the masterpage, the usercontrol or the page. using the ~ means less headaches in the long run.


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
6/2/2007 12:26:57 AM

Hi, Brian, and thanks for getting back so speedily to my quandry.

So why when I deploy a SIMPLE page that has an image reference to "~/images/myimage.jpg" does it error out?

For an example deployed (on GoDaddy ASP.NET 2.0) see this link: http://zoweeweb.com/zowee/tst%5FSimp%5F1/

You'll notice that the text indicates that there should be two copies of the same image displayed. However if you inspect the "View Source" you see that the reference to the first (which originally was "~/images ...") has become "../images..." in some translation which renders it NOT THERE.

This is the part I don't understand.  

 mahalos again ... :)  KevInKauai
 

0
KevInKauai
6/2/2007 1:01:50 AM

I probably didn't explain it properly. The ~ is like saying start at the root of the site so your image link should be ~/zowee/images/myimage.jpg. This is the whole point. It's a handy quick reference to the root of the site. In the second image it works fine because the images folder is a sub directory of the folder the page is in but if that page was in some other folder it wouldn't be as straightforward wheras the ~ will work no matter where your page is in respect to the image. 


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
6/2/2007 3:25:43 PM

But it DOESNN'T work! That's my point.

I've signed up for a "purer" ASP.NET hosting thing (about to give up on GoDaddy and move most of the accounts that I work with from there!) with UltimaHosts.net. If you will check out this page: http://1312.ultimahosts.net/tst2/

If you "view source" you'll see that the first image reference has become "../images ..." whereas it starts out in the default.aspx file as "ImageUrl="~/images/ ... "

WHAT GIVES?

mahalo, again ... :)  KevInKauai

0
KevInKauai
6/4/2007 7:58:40 AM

I have found that I need to replace the "~/" with the "../" and then all is good. I don't know why, but it's a work-around for me that works.

BTW, how's the surf?
SMc


"I have not failed. I just found 10,000 ways that don't work." - Thomas Edison
0
smcmiata
6/4/2007 5:12:08 PM

O.k. the root of that site you linked to is http://1312.ultimatehosts.net

You have set the imageUrl as "~/images/..." which says this images is located at  http://1312.ultimatehosts.net/images/.. when in fact it is located in the tst2 folder so the ImageUrl should read "~/tst2/images..."


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
6/4/2007 5:16:52 PM

I wonder since I am working with a sub-web, if that would have an effect on "~/" vs "../"  ?


"I have not failed. I just found 10,000 ways that don't work." - Thomas Edison
0
smcmiata
6/4/2007 5:46:19 PM

Thanks, SMc and Brian!

Perhaps my confusion is where I am "here".

When developing a web application (or a web site) I think in terms of the "root" of that -- which is "here". Therefore, an images folder (for example) would not be back "back and then forward" but simply a sub-folder within the folder. So why the need for "~/images" at ALL?

When I deploy, the application can go into its own sub-folder (i.e., if the "root" of the main web site is "wwwroot"), this particular "app" might go into a sub-folder called "CalcShipping", in which case an uncomplicated, un-tilded reference of "images/filename" would suffice just fine, wouldn't it? So why does this "~/" seem like a waste of my time (in terms of overriding those references and simplifying to "relative") and a plain ERROR? Is there an option to turn it OFF?

Thanks for your interest and responses ... :)  mahalos ... KevInKauai

P.S. The surf is always good in Hawaii, just sometimes a lot better than others. (I don't surf -- just snorkel.)

0
KevInKauai
6/4/2007 7:18:20 PM

If you have a folder called folder1 for example and within this you have an images folder then a page in folder1 will correctly get the image if you use "images/pic.jpg" for example. If you have another folder called folder2 and you put the same link in a page there with "images/pic.jpg" then it won't work because it looks in folder2/images/pic.jpg but the image is in folder1/images/pic.jpg. This is the point. Useing ImageUrl="~/folder1/images/pic.jpg" means this image will correctly display whether your page is in folder1 or folder20 because you are telling it to start at the root of your application then look in folder1/images/. If you never intend having sub folders in your site then maybe the images/pic.jpg will work fine for you. As I say it's a handy shortcut that you may or may not use.


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
6/5/2007 12:09:59 AM
Reply:

Similar Artilces:

Regular Expression to remove "/", "\", "<", ">" and "="
Can anyone please show me the regular expression to reject a string ("<blue", "right>" etc.) which has the following expression in it: "/", "\", "<", ">" and "="  hi, It may Help u.. it is in Class file u may use this expressin in validation controls also. Regex objReg = new Regex(@"^[^,.?/\~|`;:'<>]*$", RegexOptions.Singleline); Regex objReg = new Regex(@"^[^,][^.][^?][^/][^\][^~|][^`][^;][^:][^'][[^<][^>]$", RegexOptions.IgnoreCase);Thanks &...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Deleting "to's" and "from's" on emails
Name: Rae McFarland Email: larryatmacsmachinedotcom Product: Firefox Summary: Deleting "to's" and "from's" on emails Comments: There doesn't seem to be a way to edit and email and then forward it. Some people send something I'd like to forward, but there's a whole page of previous mailing addresses. I'd like to delete them before forwarding. I've tried and the whole email gets deleted. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16 From URL: http://hendrix.mozi...

Here's a headscratcher! "I" and "*"
We have a user, all of a sudden whenever he types in the body of a message from GroupWise (6.5.5), he can't type the letter "I" as in "me myself and I." When he does, what appears instead of an I is either an asterisk (*) or a dash (-). It's the wierdest thing and I can't find anything to even remotely describe this situation. At first I suspected his keyboard but he does not have this issue typing in Word or other applications, just GroupWise. Anyone ever see this? What in the world is going on there? (By the way, it's a really funny situa...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

"-" not "_"
I wrote a SQL statement in the data tab. I wrote a bunch of alaises as example ' word-type ' but when I hit the layout tab it converts the "-" to "_". So now my field name is ' word_type '. Is there any way to prevent this? CardGunner Don' use a hypen ( - ).  It isn't a valid character for column names.   See http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1188931,00.html   Here's an excerpt about column names: Letters as defined in the Unicode Standard 2.0 Decimal numbers from either B...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

Web resources about - What's with "~/" and NOT "~/" ? - asp.net.web-dev-2005-express

Resources last updated: 12/27/2015 7:39:23 PM