Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory
Refer to root path of asp.net project directory Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Go Back  Xtreme Visual Basic Talk > > > Refer to root path of asp.net project directory


Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2008, 10:32 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default Refer to root path of asp.net project directory


Hi Guys,

I having a small issue

Actually at the root level of my asp.net project directory i have the folder structure

app_data (folder)
default.aspx (file) - uses masterpage1
agent (folder)
masterpage1(file)

and then inside agent folder i have
masterpage2(file) - nested master page which uses masterpage1
default.aspx (file) - uses masterpage2


The problem is that in masterpage1, i have defined a link called (home) which always refers to default.aspx page (at the root level) ..i uses <a href = default.aspx>

the problem issue occurs when im in the agent folder. if im at the default.aspx
page at the agent folder, and i try to click the link "home", i dont get back to the default.aspx page at the root level, it always refers me to default.aspx in agent folder.

If i change the link <a href to ~/default.aspx>, then when im at the root default page and try clicking home, it says file cannot be found...

How do i make the <a href> always refer to root default.aspx page no matter how deep the files are located..

thanks you very much ..
Reply With Quote
  #2  
Old 07-27-2008, 01:14 PM
Qua's Avatar
QuaRefer to root path of asp.net project directory Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Code:
<a href="<% Response.Write(Server.MapPath("~/default.aspx")) %>" ></a>
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 07-28-2008, 04:50 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

<a href="<% Response.Write(Server.MapPath("~/default.aspx")); %>" >Home</a></td>


Hi,
thanks alot for the reply, but i tried, it didnt work, whenever i click the link, its not redirecting me anywhere, it just stays at the same page

my asp.net web application is based on c#
Reply With Quote
  #4  
Old 07-28-2008, 07:33 AM
AtmaWeapon's Avatar
AtmaWeaponRefer to root path of asp.net project directory AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Server.MapPath is the wrong choice because, as the documentation clearly states, it returns the physical path to the indicated file. Qua was very close, but took one too many steps.

The "~" character in any path represents the "home" directory where the project is rooted. I believe ASP .NET automatically expands this into absolute URIs as it compiles the page, but I don't have enough experience to say that with authority. So, let's say your web site is in C:\WebSite\App\Default.aspx, and you are in test\test.aspx. A link like this:
Code:
<a href="~/Default.aspx">Home</a>
...is expanded to reference "http://www.yourdomain.com/directoryToApp/Default.aspx. Server.MapPath would return "C:\WebSite\App\Default.aspx", which obviously won't help your web site users.

You might have noticed this if you paid attention to where the link actually tried to take you, rather than just noticing it didn't work.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 07-28-2008, 07:47 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

Hi,
Thanks for the response,

Actually initially, i used the following

Code:
<a href="~/Default.aspx">Home</a>
I doesnt work in my case, if you refer to my first post, my masterpage2 is nested-> derived from masterpage, so lets say im in the following link /agent/default.aspx, and im using the link above, it always goes back to default.aspx which is in the agent folder, somehow its not going back to the root default.aspx page. preety confused actually
Reply With Quote
  #6  
Old 07-28-2008, 07:50 AM
AtmaWeapon's Avatar
AtmaWeaponRefer to root path of asp.net project directory AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Hmm... I'm going to look over my notes on master pages and try to see if there's a solution, I'm pretty sure there is. I have some idea for some hacks that could work, but I'm not exactly an ASP .NET guru. I'll see if I can get this thread moved to the ASP .NET section of our forums, where it's more likely someone who knows what they're talking about (unlike me!) will reply.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 07-28-2008, 07:52 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

Quote:
Originally Posted by AtmaWeapon View Post
Hmm... I'm going to look over my notes on master pages and try to see if there's a solution, I'm pretty sure there is. I have some idea for some hacks that could work, but I'm not exactly an ASP .NET guru. I'll see if I can get this thread moved to the ASP .NET section of our forums, where it's more likely someone who knows what they're talking about (unlike me!) will reply.

Actually i have learned something new from your post on virtual and pysical path, i appreciate your response, anyway, ill do some research as well. thanks alot
Reply With Quote
  #8  
Old 07-28-2008, 08:10 AM
darkforcesjedi's Avatar
darkforcesjediRefer to root path of asp.net project directory darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

Is "Home" supposed to link to the default.aspx in the root?

As in:
Code:
http://yourdomain.com/default.aspx
And not:
Code:
http://yourdomain.com/AppPath/default.aspx
Is there a reason you cant use this?
Code:
<A HREF="/default.aspx">Home</A>
Or am I missing something?
__________________
To err is human; to debug, divine.
Reply With Quote
  #9  
Old 07-28-2008, 08:37 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

Yes, "Home" supposed to link to the default.aspx in the root

i tried /default.aspx, it fails as well.

Actually if you refer to my structure in the first post, i have 2 default.aspx page (1 in "root" and another one in "agent" folder), and 2 masterpage (1 being nested). The "home" link resides in the first masterpage.

I have tried the follwing in the "home" link

/default.aspx
~/default.aspx
servermap.path

Some didint work at all, and some either works when im in agent directory or root directory. it doesnt work in both cases.
Reply With Quote
  #10  
Old 07-28-2008, 09:11 AM
darkforcesjedi's Avatar
darkforcesjediRefer to root path of asp.net project directory darkforcesjedi is offline
Trust me, I'm an

* Expert *
 
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,964
Default

You're not providing enough information to answer the question. What are the URLs to the files you mentioned? Are these the URLs?

Code:
http://yourdomain.com/ProjectDir/app_data
http://yourdomain.com/ProjectDir/default.aspx
http://yourdomain.com/ProjectDir/agent
http://yourdomain.com/ProjectDir/masterpage1


http://yourdomain.com/ProjectDir/agent/masterpage2
http://yourdomain.com/ProjectDir/agent/default.aspx
In masterpage2, you want a link to "/ProjectDir/default.aspx". Is masterpage2 part of a different project?

You could use "~/../default.aspx". I don't use ASP.NET, but I would assume there is a better way to link from one project to another.
__________________
To err is human; to debug, divine.
Reply With Quote
  #11  
Old 07-28-2008, 09:41 AM
Qua's Avatar
QuaRefer to root path of asp.net project directory Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Atmaweapon is correct. I was a bit hasty with my answer.

The reason that <a href="~/somepage.aspx"> </a> doesn't work is because the server doesn't translate ~ into the virtual home directory in an ordinary A-tag. The server only processes such special signs in ASP-objects. So what you need to use instead is the <ASP:HyperLink>-control. In the following code where the Hyperlink control is used the server correctly translates the ~ into your virtual home directory
Code:
<asp:HyperLink ID="HyperLink1" NavigateUrl="~/SomePageInHomeDirectory.aspx" runat="server">HyperLink</asp:HyperLink>
'In your source code on client side you'll see this code:
<a href="www.yourhomepage.com/SomePageInHomeDirectory.Aspx> Hyperlink </a>
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #12  
Old 07-28-2008, 10:24 AM
a1jit a1jit is offline
Junior Contributor
 
Join Date: Oct 2004
Posts: 293
Default

hello qua,
thanks alot ..you solved my problem, appreciate it..now im able to sleep peacefully,

thank you all for ur contributions.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
 
Refer to root path of asp.net project directory
Refer to root path of asp.net project directory
 
-->