ASPNET ~ doesn't really work all the time

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?
 
M

Michael Nemtsev [MVP]

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>
 
S

sturyuu5eye

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.
 
J

Jonathan Wood

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.
 
J

Juan T. Llibre

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.
 
C

Cowboy \(Gregory A. Beamer\)

~ means application home, BUT only in controls. You cannot simply add it to
a static element. It does not work that way.
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top