473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Resolve url problem with asp.net tilde ("~")

Hi all,

I have a problem which I don't understand with the "~" mark in a
NavigateUrl property of an asp:HyperLink. I have this in a master page,
to build the standard menu (rMenuItems is a Repeater):

Protected Sub rMenuItems_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(e.Item.FindControl("lnk"), HyperLink).NavigateUrl =
DataBinder.Eval(e.Item.DataItem, "Url")
End If
End Sub

It works well, if the url in the browser is at root. Example, if I am
at : http://localhost/faq.aspx, it works.

As soon as I am not in the root directory, e.g.:
http://localhost/test/test.aspx, the links now all point to a location
in the subfolder. e.g.: the link who was mapped with "~/default.aspx"
points at http://localhost/test/default.aspx in the browser.

Anyone knows the correction for this one?...

thanks!

ibiza

Feb 19 '06 #1
4 14586
The tilde represents the root of the web application. So, if you make the
test subdirectory an application in IIS, then you can use the tilde for
http://localhost/test .
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"ibiza" <la******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have a problem which I don't understand with the "~" mark in a
NavigateUrl property of an asp:HyperLink. I have this in a master page,
to build the standard menu (rMenuItems is a Repeater):

Protected Sub rMenuItems_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(e.Item.FindControl("lnk"), HyperLink).NavigateUrl =
DataBinder.Eval(e.Item.DataItem, "Url")
End If
End Sub

It works well, if the url in the browser is at root. Example, if I am
at : http://localhost/faq.aspx, it works.

As soon as I am not in the root directory, e.g.:
http://localhost/test/test.aspx, the links now all point to a location
in the subfolder. e.g.: the link who was mapped with "~/default.aspx"
points at http://localhost/test/default.aspx in the browser.

Anyone knows the correction for this one?...

thanks!

ibiza

Feb 19 '06 #2
well actually my problem is that the tilde does not seem to point at
the root of the application, which is what I want. To clarify, if I am
on a page at the root, like http://localhost/index.aspx, my menu link
which had the NavigateUrl as "~/faq,aspx" correctly points at
http://localhost/faq.aspx, which is correct in that case.

However, as soon as I am in a page in a sub directory, like
http://localhost/test/test.aspx, the same link which the NavigateUrl is
the same "~/faq,aspx" now points to http://localhost/test/faq.aspx,
which is incorrect.

The tilde does not seem to be taken in count, how is that?

Feb 19 '06 #3
This is not incorrect. Your subdirectory test is also an application in
IIS, therefore it can also be represented by the tilde. It's all a matter of
perspective from IIS. If you call an ASPX page in the root directory, then
the application is http://localhost; however, if you call an ASPX page in
the test subweb, then the application is http://localhost/test. They are
treated by IIS as two separate applications. As such, the tilde will
represent two separate applications. Thus, when you call ~/faq.aspx from
the test application, it has to assume that the path is
http://localhost/test.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"ibiza" <la******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
well actually my problem is that the tilde does not seem to point at
the root of the application, which is what I want. To clarify, if I am
on a page at the root, like http://localhost/index.aspx, my menu link
which had the NavigateUrl as "~/faq,aspx" correctly points at
http://localhost/faq.aspx, which is correct in that case.

However, as soon as I am in a page in a sub directory, like
http://localhost/test/test.aspx, the same link which the NavigateUrl is
the same "~/faq,aspx" now points to http://localhost/test/faq.aspx,
which is incorrect.

The tilde does not seem to be taken in count, how is that?

Feb 19 '06 #4
ok, thanks for the follow-ups.

But my problem is still present, as in my example, /test is not
configured as an application, in fact the directory does not even
exists on the server! I used a custom error 404 page to redirect
correctly when a url is wrong (for example http://localhost/test, as it
cannot find the 'test' directory), according
to the url (e.g.: if I type http://localhost/faq, I do a
server.transfer to http://localhost/faq.aspx, and if I type
http://localhost/test/yeah, I will be redirected to
http://localhost/test.aspx?dir=yeah).

To resume, my menu link with its NavigateUrl property set to "~/faq"
(now that I explained that I have custom error page redirection)
correctly redirects me to the correct "http://localhost/faq" page if
the url in my browser is not a subdirectory and redirects me to the
incorrect/inexistent "http://localhost/SUBDIR/faq" page if the url in
my browser contains SUBDIR.

I included an example of a correct and incorrect scenario screenshots,
depending on the url in the browser to help better understand.

http://img380.imageshack.us/img380/7554/tilt7om.gif

Hope this is enoughe to solve my problem!

Thanks a lot all for your time

Feb 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: monte | last post by:
Hello, I need to parse a tilde delimited file and output it to a tabbed delimited file. Example file example.txt data1~data2~data3~data4 data5~data6~data7~data8 I need to extract data2,...
1
by: MB2 | last post by:
I have code in a User Control for an image button like this: <asp:ImageButton id="__0" runat="server" text="Delete" ImageUrl="~/Images/ImageLibrary/icon_delete.gif" /> This used to work and it...
10
by: Shawn | last post by:
Hi, For a few years, I have been developing each of my clients websites using a seperate web site (unique IP) to solve problems with relative URL's between my local dev station and the...
3
by: mark | last post by:
I have a procedure that needs to put characters into the current insertion point of a textbox. This insertion point is not necessarily the end of the current string so textbox1.text &= "?" won't...
1
by: Mythran | last post by:
In other web servers, more specifically apache and even non-web servers you can use the tilde character to specify the root directory, or home. Before I go reinventing the wheel (by parsing a...
7
by: ibiza | last post by:
Hi all, I have a problem which I don't understand with the "~" mark in a NavigateUrl property of an asp:HyperLink. I have this in a master page, to build the standard menu (rMenuItems is a...
8
by: otto | last post by:
Hi, all: I have a problem with the inclusion of .js files in mu .aspx pages when using Master Pages. I try to explain it. If I make a web project without master pages I simply put in the head...
48
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The...
4
by: =?Utf-8?B?QWxm?= | last post by:
Hello all, I am having trouble dealing with ~(tilde) in my .Net 1.1 web application, specially when it comes through the URL. For example, when someone requests the following URL:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.