|
 |
aspdotnet_website_programming thread: Use of Relative References in various places ...
Message #1 by "Frank Kurka" <wrox@f...> on Sat, 20 Jul 2002 15:21:04
|
|
I've been trying to covert ThePhile to a version that can be simply copied
to a new virtual directory (e.g. ThePhile2/, ThePhile3/ etc.).
This means coming up with a universal reference approach that changes all
fixed absolute references to relative absolute references that can point
to any root, but start from that root, in the html, xml, directives, etc.
The problem seems to be that there is no simgle approach that works in all
the technoliges (html, xml, .net framework).
1) Some cases, the tilde slah works (~/) (src= "`/Modules/xxx")
2) Some cases, the "Modules/xxx" works, but not in all cases.
3) In some config files neither works (navigator.xml) and requires
the /ThePhile/ fixed reference.
Usually the ../../Modules/xxx works, but it is not a "relative absolute
path" and breaks if pages are moved.
Looking for a way to universally specifiy the app root, or define a single
string that could point to it.
This problem does not include namespaces or assemby names because they can
move to any application without changes.
The idea to to be able to copy the app to a new app and not have to make
200+ changes to the new app name.
Got a solution?
Message #2 by "Shannon Horn" <shannon_horn@w...> on Sat, 20 Jul 2002 09:44:07 -0700
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0002_01C22FD2.00584E20
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Well, this may not be what you are looking for but is a related bug in
ASP.NET that we were credited with finding. I'll share it just in case
it is one of your difficulties. Many Web hosts require that you use
virtual paths instead of file system based paths when referencing
external files, especially SSI. The way to use virtual paths is to
include the HTML/XHTML base tag in your pages. This tag specifies the
root of your Web application and then all paths in your application (at
least on the pages that the base tag is included in) must be relative to
this path.
For instance, if I have a page that uses the base tag as follows:
<base href="http://www.webgeniuses.com <http://www.webgeniuses.com/> "
/>
then all paths in that page must adhere to this page as the root or they
will be invalid. I normally organize my Web projects into folder
structures such as:
Root
-- Controls
-- Forms
-- Images
-- Styles
And so on. Thus, if I'm coding in a page that is located in the Forms
folder and want to reference an image in the Images folder, my img tag
in the page would resemble:
<img src="Images/MyImage.gif" />
Notice that this path comes straight off the root and does not use the
"../" that you might expect with a file based path. Again, this is
required by many Web hosts now who restrict the use of file based paths
for security purposes.
The problem arises in the form tags. In traditional ASP, the action
attribute of the form tag referenced the next ASP page that you would be
posting your form values to. In ASP.NET, however, this paradigm has
changed and all ASP.NET pages are created as self posting pages. If you
want to post results to another page, you must do so in the code behind
page. There are a few ways to do this but the most common is to store
your values to be passed into Session variables and then use
Response.Redirect to post to the next page.
Even so, if you are using the HTML/XHTML base tag, and want to post back
to the same page or create a self posting page and your pages reside in
a sub folder, such as mine do, you will end up with an HTTP 404 error in
ASP.NET. This is because ASP.NET will always overwrite anything you put
in the action attribute of a server side form tag with simply the name
of the current page in an attempt to force it to be a self posting page.
For instance, if I'm using the HTML/XHTML base tag to control my paths,
my action attribute of my form tag would be:
<form action="Forms/MyForm.aspx" method="post" runat="Server></form>
This makes sense with the folder structure and paths, however, since
ASP.NET overwrites this action attribute in every case on a server side
form tag, the page sent to the client will have a form tag of:
<form action="MyForm.aspx" method="post" runat="Server></form>
where MyForm is the name of the current page in both cases. As you can
see, if this page is sitting in the Forms folder and I am using the
HTML/XHTML base tag, this will be pointing to a page sitting in the root
and not in the sub folder and we will receive an HTTP 404 error as soon
as we attempt to submit the form.
This is a confirmed bug in ASP.NET and there is no work around for it
that we have been able to find. We just simply cannot combine ASP.NET,
the base tag, and sub folders. Since you are looking for path options,
you might stumble across this and be perplexed or frustrated like we
were.
However, keep in mind that the base tag affects only client side coding.
Even if you do use an option such as this, your server side paths will
always be in reference to the server's file system.
-----Original Message-----
From: Frank Kurka [mailto:wrox@f...]
Sent: Saturday, July 20, 2002 15:21
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] Use of Relative References in
various places ...
I've been trying to covert ThePhile to a version that can be simply
copied
to a new virtual directory (e.g. ThePhile2/, ThePhile3/ etc.).
This means coming up with a universal reference approach that changes
all
fixed absolute references to relative absolute references that can point
to any root, but start from that root, in the html, xml, directives,
etc.
The problem seems to be that there is no simgle approach that works in
all
the technoliges (html, xml, .net framework).
1) Some cases, the tilde slah works (~/) (src= "`/Modules/xxx")
2) Some cases, the "Modules/xxx" works, but not in all cases.
3) In some config files neither works (navigator.xml) and requires
the /ThePhile/ fixed reference.
Usually the ../../Modules/xxx works, but it is not a "relative absolute
path" and breaks if pages are moved.
Looking for a way to universally specifiy the app root, or define a
single
string that could point to it.
This problem does not include namespaces or assemby names because they
can
move to any application without changes.
The idea to to be able to copy the app to a new app and not have to make
200+ changes to the new app name.
Got a solution?
|
|
 |