Current web directory changes?

  • Thread starter Thread starter TPS
  • Start date Start date
T

TPS

I am using relative pathing in my menus that call up additional pages

If I click the "signup" menu it calls "signup.aspx" in the web root folder
If I click the "register" menu it calls "resister.aspx" in the web root
folder

If I click the "upload" menu, it calls "secure/upload.aspx" in the
webroot\secure folder

After I bring up the upload.aspx file, my new "current directory" is the
"webroot\secure" folder and all of my links that point to pages in the
webroot break.

Why is this "current directory" setting changing just by calling up a page
in a subfolder?

Thanks.

tps.
 
Why would you think it wouldn't change? I mean you ARE opening a page in a
subfolder.
Simply set all your page references with a "/" at the begining to ensure
relativity from the web root
 
Curt thanks for your reply.
subfolder.

My other websites do not behave this way. I expect all paths to be relative
to the root.

menu page with these links is in the root.
link: subfolder/mypage.aspx
Should not change the behavior of
link: mypageinroot.aspx

The server looks a the path and finds the file and sends it to the browser.
The server does not "move" to that subfolder for all future requests, it
stays put at the root. The next request is served out from the perspective
of the root.

What am I missing here?
 
are your "other" sites using seperate pages or CONTROLS.
every call is always relative to where the PAGE you are on is. If you don't
path it all out you will always be relative to where you are now.
 
Simply set all your page references with a "/" at the begining to ensure
relativity from the web root

This is what I did in the first place and things did not work, so I moved to
my other plan of thinking everything was relative to the root and that did
not work.

I wonder if you could shed some light as to why adding "/" to the begining
of my paths is not working.

My dir structure

root
root/base
root/secure
root/images


My style sheets are being ignored:
<link rel="STYLESHEET" type="text/css" href="/CPO.css">
<link rel="STYLESHEET" type="text/css" href="/Base/CPOLayout.css">

And images are not being found:
<IMG src="/images/mtn4a.jpg">

Both of these are working if I take the "/" out of the begining.

I do not want to put the full web addres in because this is a dev machine
and there will be to many places to switch back and forth from the read
domain name.

Ideas?

Thanks.

tps.
 
Okay I figured it out.

My dev machine is running xp pro and iis only supports multiple vir dirs
instead of multiple websites. So putting "/" in front of my paths creates
links like this:
http://localhost/mypage.aspx.

but the real path is :

http://localhost/my vir dir/mypage.aspx.

Seems the only solution is to path is all the way out, but as I mentioned in
my earlier post, that is going to be a maintenance nightmare when I move
pages to the real website.

How is everyone else handling this situation?

tps.
 
I do it with everything being ONE folder level deep

root/pages
root/images
root/controls
root/blah

then I path EVERYTHING with a
.../dir/file.ext

It's always starting at the root of my site, not the root of the server that
way.
 
Curt.

1. Are you developing on a "non" windows server machine, like xp pro or
win2000 ? This distinction must be made because of the way vir dirs are
handled on a compared to "real" websites on a server

So if you are running on a work station then...

Lets say our single website is called "Mywebsites". It is located in
"d:\inetpub\wwroot"
And our vir dir is called "testweb", and it is located in
"d:\inetpub\wwroot\testweb"

2. Could you check the properties sheet of one of your virtual directories
and tell me what the "starting point" is in the "Application Settings" area,
under the "Virtural directory" tab. On my system the "Starting point" is
"<Mywebsites>\testweb"

Now if we are both on the same configuration page, the this is how my system
handles links.

I am going to put my login.aspx page in the "secure" folder of my vir dir,
d:\inetpub\wwroot\testweb\secure\login.aspx".

Here are html and their browser links:

<a href="/secure/login">Login4</a>
http://localhost/secure/login.aspx
with the desired "/" in front of the link the server will try and serve up a
page in "d:\inetpub\wwroot\secure\login" and this folder does not exist.


<a href="secure/login.aspx">Login3</a>
http://localhost/testweb/secure/login.aspx
this works, but we don't have the desired "/" in front of the path. And as
you stated before "If you don't path it all out you will always be relative
to where you are now."

<a href="../secure/login.aspx">Login5</a>
http://localhost/secure/login.aspx
same as above

<a href="login.aspx">Login1</a>
http://localhost/testweb/login.aspx
this would work if the file was in the root of my virdir, but it is not, and
we do not have the desired "/" in front of the path.

<a href="/login.aspx">Login2</a>
http://localhost/login.aspx
this would not work because http://localhost points to "d:\inetpub\wwroot"
and not my testweb folder

Comments and or ideas?

Thanks for helping.

tps.
 
Hi TPS,


Thank you for using Microsoft Newsgroup Service. Based on your description,
you problem seems to be that you use relative url path in all of your pages
and the current directory will change when the page is in diferent folders
such as root or sub folders. Then, you found some of the relative links
will point to incorrect path, yes?


As for this problem, generally in web page, there're two means to specify
the path fo the web link.
1. Using the absolute path, which need to output the full url path of a
resource. In fact,in ASP.NET web application, use "/" based url is also
some thing like absolute path since it'll have you to hard code the Virutal
Directory's name in the path. And as you mentioned, that'll cause many
troubles when you move the web project to another places.

2. Using the relative path. The relative path is based on the current
directory. So when you have the weblinks point to a same resource in pages
in diferent folder. You need to code the url path differently. For example,
we have such folder structure:
web root/
MyWebApp/
Main.aspx
About.aspx
.....
SubFolder/
Login.aspx
.....

Then if we have a link in both the Main.aspx and Login.aspx which point to
the About.aspx. We need to code the url differently in the two pages(if you
use relative path):
In Main.aspx:
href="About.aspx"
In Login.aspx:
href="../About.aspx"

So as for your situation, do you think it possible that you use different
url in the menu in the diferent folder's page?

Please check out my suggestion. If you have any questions, please feel free
to post here.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steve, thanks for your reply.

I have been building and managing our company website for 5 years, so I am
familiar with relative and absolute pathing. This situation seems
different.

I am implementing a "Master pages" solution, where my menu, banner, and
footer are "built" around the page that is to be displayed. So I only have
one location where my navigation links reside.

So here is the problem.

Lets say our single website is called "Mywebsites". It is located in
"d:\inetpub\wwroot"
And our virdir is called "testweb", and it is located in
"d:\inetpub\wwroot\testweb"

You should be able to use "absolute" pathing by putting a "/" in front of
your url paths.

example:
If I have a page in the "secure" folder :
"d:\inetpub\wwroot\testweb\secure\login.axpx"

then, I should be able to create my links like so:

<a href="/secure/login">Login</a>

but when you hover over the link this is what you get:
http://localhost/secure/login.aspx

the secure folder is NOT in the "d:\inetpub\wwroot\" folder

it is in the "d:\inetpub\wwroot\testweb\" folder

The problem is my website (because I am not on a server) is in the testweb
virdir folder, not the root of the iis web.
http://localhost/testweb/

the link should be:
http://localhost/testweb/secure/login.aspx


Thanks for your help.

TPS.
 
Hi TPS,


Thank you for the response. I've got that your've used a "Master Page" to
render out the common layout of serveral pages, so all the Page's Navigator
menu(include hyper link) are renderrd in the "Master Page". That causes the
problem on relative url in different folder hierarchy.

As for this problem, do you think it possible to set the url path
dynamically by code when the "Master Page" class is generated? For exmaple,
our web application is in named "TestWeb" and in the "TestWeb" Virtual
Directory, and have below structure:
site root/
TestWeb/
...aspx pages
security/
Login.aspx
....aspx pages

In the master page, we've a menu's hyperlink which points to the Login.aspx
in the "security" sub dirctory. We can set the hyperlink as "runat=server"
control like:
<a id="lnkLogin" runat="server" href="security/Login.aspx">Login Page</a>

Then, in the Masterpage's code-behind file ,we can add such inital code for
it:

lnkLogin.HRef = HttpContext.Current.Request.ApplicationPath + "/" +
lnkLogin.HRef;

the "Request.ApplicationPath" will return the Web application's root page ,
for the "TestWeb" application, it returns
"/TestWeb" , then when the final page render out, view its source in IE,
the hyperlink is like:
<a href="/WebAsmTest/security/Login.aspx" id="lnkLogin">Login Page</a>

When hover on it, the url path is shown as: http://web site
name/WebAsmTest/security/Login.aspx
This is the correct path for the Login page. Also, we can locate other
pages in the same way.

Please try out the suggestion to see whether it helps. If you have any
questions, feel free to post here.



Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi TPS,


Have you had a chance to try my preceding suggestion or have you resolved
the problem? Please feel free to let me know if you have any questions or
need any assistant.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi TPS,


As for the absolute URL problem in our issue. I've reviewed some further
references and asked for some experts. Here is some infos I got:

When we have some links in a web document on a site. For example:
http://websitename/webapp/main.aspx
"webapp" is the vdir name

If we set the web links in main.aspx such as <a
href="/secure/protected.aspx" >/secure/protected.aspx</a>

Then, in the client browser, when wo hover over the link , the status bar
will display as below:
"http://websitename/secure/protected.aspx" which is not the correct value.
However, this isn't caused by the IIS. If we view the source in the client
browser, we can see that the hyperlink's value is still as:
<a href="/secure/protected.aspx" .....

So in fact, the "http://websitename/secure/protected.aspx" is generated via
the browser, the client browser stored the current directory info and then
construct the abosolute url path and request the file from the server. IIS
never modify the request url (no matter the version for server machine or
workstation machine).

And as for using relative url in web link, noramlly we need to specify the
url diferently depend on its folder hierarchy. As for the situation in our
issue(using a Master Page to contain the common menu link ), I think you
may consider the suggestion in my last reply. If you still have anything
unclear on this issue, please feel free to post here. I'll be willing to
help you.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steve, thanks for your further information.

I know I could do the "dynamic" pathing by building the path each time the
page gets built, but I still do not understand why I can't use relative
pathing. Something is wrong if I can't use links like this:

/mypage.aspx
/secure/mysecurepage.aspx
/secure/area1/myotherpage.aspx

All links start at the top and go down, this is the way I have been
developing for years, so what has changed?

Thanks again for your help.
 
Hi TPS,

Thanks for your response. As you said that the situation is different on
another server where the path with "/" start all from
the Virtual Directory's root, not from the site root, yes? As I mentioned
that the problem with the path maybe concerned with the client's browser,
Would you try using the new browser to visit the old site which doesn't
have the path problem? Because I've also tried visit the same style links
start with "/" on win2k server machine or WINXP workstation, but the result
are the same. They start from the website's root , not the virtual
directory's root.

If the certain server does haven't the problem. Would you have a further
check between the two machines to see whether there are anything else
different? Or can you provide me the setting of such a server's IIS
enviroment and the application's setting so as for me to repro the case on
my side? Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi TPS,

Have you had any progress on this issue? Please feel free to let me know if
you need any assistance.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
before you dive into mucking with generations etc, back up a bit and
re-examine your data structures and resource alloc/deallocation.

If you use datasets/datareaders, are you being carefull to null them out
when they are no longer in use. Are you closing your connections. Have you
guarded blocks of code with a finally construct or a catch handler to ensure
that resources are being cleanup up neatly. Have you considered replacing
string concatenations with stringbuilder for intense string manipulation.
Are you examining the number of exceptions and where they are coming from to
determine if they are causing memory leaks. Are you making use viewstate to
ease the load on the server. are you using caching effectively instead of
establishing new connections to grab repeat data requests?

The solution is probably in these unanswered questions. When you start
scaling a web application upward, these factors collectively make or break
an application.
 
Back
Top