What does this symbol "~" mean in the web.config appsetting - path

<add key="ImageStore" value="~/UserMedia" />
I have this variable specified and up to now it was working. It just stopped for some reason two days ago. "UserMedia" is a virtual directory in the root of the website, which is mapped to "c:\inetpub\wwwroot\UserMedia" but when the page gets called, I get the path relative to the directory of the .asp page instead.

The tilde character "~" generally means "Root Directory" in .NET web type projects, and usually refers to the root of the website.
So, "~/UserMedia", is likely part of a file path.

Related

Path-relative URIs for resource files VS routes that "look-like" sub-directories

I'm using the URL like web.com/sys/test, which is rewritten in nginx config to web.com?system=sys&id=test via rewrite ^/(\w+)/(\w+)$ /?system=$1&id=$2 break;.
Also, all my resource files have relative path.
Therefore I get error:
Unable to find web.com/sys/css/user.css, however user.css is located in /css/.
Is there a way to solve the problem remaining the relative path for resource files?
Used base tag:
<base href="/">
However, in some cases this method may just add a whole lot of new problems. Look at this link

Technical terminology - URL Paths types: Absolute, relative, and

I understand that an absolute path is of the type:
http://www.example.com/thisdir/4/5uy3/2/s.js
and also, that relative paths are of the type:
5uy3/2/s.js (in relation to directory "4")
but what is the term for the type of path that is prepended with a slash to reference back to the root? For example, if someone was working on a script in s.js, he/she might use /thisdir/4/5uy3/2/s.js when including that javascript from different directories to avoid having to consciously think about the current working directory when including it.
Do you know what this type of path is called?
From Dreamweaver / About linking and navigation
There are three types of link paths:
Absolute paths (such as http://www.adobe.com/support/dreamweaver/contents.html).
Document-relative paths (such as dreamweaver/contents.html).
Site root–relative paths (such as /support/dreamweaver/contents.html).
The term "application root" would be the same as "site root" except that the site must be an application.

Why should I use #Url.Content("~/blah-blah-blah")?

I can't understand the benefit(s) that I can get from Url.Content() method in ASP.NET MVC. For example, you see src='#Url.Content("~/Contents/Scripts/jQuery.js")'. Why should I use it? What reasons might exist for using it? What benefits, advantages, etc. over using plain old simple references like src='/scripts/jquery.js?
Update: Based on the answers, I'd like to know if there is any other reason for using it, other than handling virtual folders? Because I haven't seen using virtual applications that much (which of course doesn't mean that it hasn't been used that much).
Usually, your web application is published as: www.yoursite.com/. The ~ character matches the root of the site /.
However, if you publish your site withing a virtual directory www.yoursite.com/mywebapp/, the the ~ character would match "/mywebapp/".
Hard-coding Urls with "/" character would cause wrong page references.
Mapping virtual paths is it's only purpose.
If you do not ever need to map them and are sure your app or it folders will not sit under other apps then it won't serve you any purpose.
From the docs note if you don't use ~ you get no change in the result anyways:
"Remarks
If the specified content path does not start with the tilde (~) character, this method returns contentPath unchanged.
"
It is usefull if your applications root path is not the root path of your server. Url.Content("~/") returns the root folder of your application.

remove application name from URL

my site uses JSF and the url appears to be, http://mysitename.com/wompower6/faces/home.xhtml
I am using prettyfaces, so if I use the following in pretty-config.xml, i can change the name to http://mysitename.com/wompower6/home
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/faces/home.xhtml" />
</url-mapping>
my questions are
how can i remove the application
name wompower6 , so that the url
becomes mysitename.com/home ?
in my web.xml, i have
<welcome-file>home.xhtml</welcome-file>,
but this does not seem to work. When
i type, mysitename.com, it does not
get mapped to home.xhtml. any clue
here?
how can i remove the application name wompower6 , so that the url becomes mysitename.com/home?
This is a webapp <Context> setting and configuration is dependent on the servletcontainer used. If you're for example using Tomcat, then there are basically 2 options to make your webapp the root webapp.
Rename the WAR file to ROOT.war and Tomcat will by default deploy it on context root.
Set path attribute of <Context> element in Webapp/META-INF/context.xml (or Tomcat/conf/server.xml, depending where you'd like to define it) to an empty String. E.g.
<Context path="" ...>
Other containers support similar constructs. Consult their documentation for detail. If you're using an IDE like Eclipse, then you can also set it in the Web Project Settings property of the project properties (rightclick project and choose Properties). Set the Context root value to just /.
in my web.xml, i have home.xhtml, but this does not seem to work. When i type, mysitename.com, it does not get mapped to home.xhtml. any clue here?
I assume that you're talking about the <welcome-file> setting. This has to point to a physically existing file, not to a virtual URL, such as /faces/*. There are basically two ways to overcome this:
Provide a physically existing /faces/home.xhtml file (it can even be left empty).
Replace the ugly /faces/* URL pattern of the FacesServlet mapping in web.xml by *.xhtml so that it will just kick in on every request for a XHTML file.
<url-pattern>*.xhtml</url-pattern>
This way you don't need to fiddle with /faces/* URL patterns.

What does a dot mean in a URL path?

In a question regarding a jQuery Ajax problem, the asker was trying to use a . in the beginning of a relative URL. I advised him to remove it, but have no idea what a dot actually does there.
His relative URL looked like this:
./delete-misc/test-ajax-code.php
I tried looking in the RFCs, without success. I know what the dot does in command line (either Linux or Win), it represents the current directory.
I'd like to know: how does this work on the Internet in a URL? Does it have any best-practice uses? Detailed explanations are most welcome.
The path segment . is typically used at the begin of relative path references and are removed during the reference resolution, i.e. the process of resolving a relative URI reference to an absolute URI:
The path segments "." and "..", also known as dot-segments, are
defined for relative reference within the path name hierarchy. They
are intended for use at the beginning of a relative-path reference
(Section 4.2) to indicate relative position within the hierarchical
tree of names. This is similar to their role within some operating
systems' file directory structures to indicate the current directory
and parent directory, respectively. However, unlike in a file
system, these dot-segments are only interpreted within the URI path
hierarchy and are removed as part of the resolution process (Section
5.2).
There is Remove Dot Segments algorithms that describes how these dot segments are to be interpreted in a certain base path context.
In your case both ./delete-misc/test-ajax-code.php and delete-misc/test-ajax-code.php are equivalent. But there are cases where a relative path can be misinterpreted as an absolute URI, e.g. having a : in the first path segment like search:foo that is different to ./search:foo as the former is an absolute URI while the latter is a relative URI path.
A ./ in front of the URL is equivalent to the current path. So ./delete-misc/test-ajax-code.php and delete-misc/text-ajax-code.php are both relative paths. In the answer you posted, you asked to remove the dot only, so the path of /delete-misc/test-ajax-code.php would translate as an absolute path instead of a relative path.
Edit: one more thing - . is the current directory and .. is the parent directory. As phihag comments, these really should be avoided and protected against in code. Directory traversal can be used for evil.
Now for a Simpler Explanation...
. and .. are NOT equivalent!
./ and ../ are NOT equivalent!
. and ./ ARE equivalent to
In all cases, . and ./ are the same as or "" or no path so not needed or used on the Web.
. (dot) is a relic of old UNIX pathing systems and NOT used on the World Wide Web for creating paths! Why? Because the dot in paths is redundant and equivalent to "" or no path or the current file directory you are in. The same result applies to using ./. It is the same as "" or no path. Both just reference the local directory your file is in ("./webpage.html" = "webpage.html").
What Path Should I Use?
So NEVER use . or ./ as both paths are irrelevant!
ALWAYS use ../ which is a RELATIVE PATH and says go up one folder.
ALWAYS use / which is an ABSOLUTE PATH and says starts from the website root folder.
Want More Proof?
Check out the result for these image paths. Assume you are referencing these paths from an HTML web page stored in the root of the web site:
SUCCESSFUL PATHS ("../" and "/" paths work well on the Web)
<img src="../images/photo.jpg" />
<img src="/images/photo.jpg" />
REDUNDANT PATHS ("." not needed)
<img src="/images/./photo.jpg" />
...same as...
<img src="/images/photo.jpg" />
<img src="/images./photo.jpg" />
...same as...
<img src="/images/photo.jpg" />
FAILED PATHS ("." in paths that fail on the Web)
<img src="/images/.photo.jpg" />
<img src="./images/photo.jpg" />

Resources