Current web directory changes?

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

Curt_C [MVP]

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
 
T

TPS

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

Curt_C [MVP]

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

Steven Cheng[MSFT]

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.)
 
T

TPS

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

Steven Cheng[MSFT]

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

Steven Cheng[MSFT]

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

Steven Cheng[MSFT]

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.)
 
T

TPS

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

Steven Cheng[MSFT]

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

Steven Cheng[MSFT]

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.)
 
A

Alvin Bruney

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.
 

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
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top