ASPNET ~ doesn't really work all the time

  • Thread starter Thread starter CKKwan
  • Start date Start date
C

CKKwan

In Unix the ~ sign is used to refer to the home directory.

And it is quite handy when used in Html pages where we can have it
moved around when deploying in different server.

However, this is not always working in IIS. Did I missed something?
 
Hello CKKwan,

Could you demonstrate the sample of what exactly doesnt work?!

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


C> In Unix the ~ sign is used to refer to the home directory.
C>
C> And it is quite handy when used in Html pages where we can have it
C> moved around when deploying in different server.
C>
C> However, this is not always working in IIS. Did I missed something?
C>
 
Say for example, in my Master page, I have something like this.

<a href="/Content/Profile.aspx" class="NavMenu">

It works, but if I put a ~ in front.

<a href="~/Content/Profile.aspx" class="NavMenu">, it will appear as:

http://localhost:1234/~/Content/Profile.aspx

And IIS complain that this page cannot be found.

Did I made any mistakes or I have to tell IIS where is my *home*
directory is?

Thanks in advance.
 
The ~/ syntax has nothing to do with IIS. Rather, it is used by many
routines within ASP.NET.

In your example, you're not using the runat="server" attribute and so it is
never even evaluated by ASP.NET. It simply is transferred to the client
unchanged.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Say for example, in my Master page, I have something like this.

<a href="/Content/Profile.aspx" class="NavMenu">

It works, but if I put a ~ in front.

<a href="~/Content/Profile.aspx" class="NavMenu">, it will appear as:

http://localhost:1234/~/Content/Profile.aspx

And IIS complain that this page cannot be found.

Did I made any mistakes or I have to tell IIS where is my *home*
directory is?

Thanks in advance.
 
re:
!> However, this is not always working in IIS. Did I missed something?

~ only works in aspx pages...to reference the root/home directory of an ASP.NET application.
~ doesn't work for html pages.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Well, it works also in links:

<link type="text/css" rel="Stylesheet" href="~/NewFolder1/Stylesheet1.css"
/>

As the others have said, it will work in controls with runat="server":

<img src="~/NewFolder1/myImage.jpg" runat="server" />


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Back
Top