473,625 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Item DataBound(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Repe aterItemEventAr gs)
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
CType(e.Item.Fi ndControl("lnk" ), HyperLink).Navi gateUrl =
DataBinder.Eval (e.Item.DataIte m, "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 14600
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.goo glegroups.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_Item DataBound(ByVal sender As Object, ByVal e
As System.Web.UI.W ebControls.Repe aterItemEventAr gs)
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
CType(e.Item.Fi ndControl("lnk" ), HyperLink).Navi gateUrl =
DataBinder.Eval (e.Item.DataIte m, "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.goo glegroups.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
2785
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, data4, data6 and data8 from the above file and output it to a file delimited by tabs: data2 data4 data6 data8
1
3713
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 would display the image properly. However, since installing the latest service pack for the .NET Framework 1.1, the tilde seems to be expanding improperly. The code that is expanded to shows this: <input type="image"...
10
1600
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 production server. Recently, I have needed to collaborate with other developers using Source Safe. But, in order to get source safe working properly, you really need to be working in virtual directories of the default web site.
3
24425
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 do. I have found that using sendkeys does the trick: Private Sub UserControl11_buttonpress(ByVal text As String) Handles UserControl11.buttonpress System.Windows.Forms.SendKeys.Send(text) End Sub
1
2215
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 tilde in the web controls for iis) is there a setting that allows similar functionality in IIS? Thanks, Mythran
7
2796
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 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
8
2385
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 tag on each page the reference to the ..js file I want to use. Because I want client side includes I make the reference with <script> tag, for example: <head runat=server> <script src="/javascript/test.js" /> </head>
48
3350
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 "toupper" function imposes a further constrait in that the value passed to it must be representable as a unsigned char. (If C does not require all character values to be positive, then again, this constrait too escapes me... ) Let's say we have the...
4
4433
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: www.mysite.com/~mypage.aspx, my web application will through the following error (with custom errors turned off): Server Error in '/' Application. --------------------------------------------------------------------------------
0
8253
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6116
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.