Server.MapPath specifies the relative or virtual path to map to a physical directory.
Server.MapPath(".")
1 returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..")
returns the parent directory
Server.MapPath("~")
returns the physical path to the root of the application
Server.MapPath("/")
returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
An example:
Let's say you pointed a web site application (http://www.example.com/
) to
C:\Inetpub\wwwroot
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop
For example, if you call Server.MapPath()
in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342
then:
Server.MapPath(".")
1 returns D:\WebApps\shop\products
Server.MapPath("..")
returns D:\WebApps\shop
Server.MapPath("~")
returns D:\WebApps\shop
Server.MapPath("/")
returns C:\Inetpub\wwwroot
Server.MapPath("/shop")
returns D:\WebApps\shop
If Path starts with either a forward slash (/
) or backward slash (\
), the MapPath()
returns a path as if Path was a full, virtual path.
If Path doesn't start with a slash, the MapPath()
returns a path relative to the directory of the request being processed.
Note: in C#, @
is the verbatim literal string operator meaning that the string should be used "as is" and not be processed for escape sequences.
Footnotes
Server.MapPath(null)
and Server.MapPath("")
will produce this effect too.
Session.Abandon()
destroys the session and the Session_OnEnd event is triggered.
Session.Clear()
just removes all values (content) from the Object. The session with the same key is still alive.
So, if you use Session.Abandon()
, you lose that specific session and the user will get a new session key. You could use it for example when the user logs out.
Use Session.Clear()
, if you want that the user remaining in the same session (if you don't want the user to relogin for example) and reset all the session specific data.
Best Answer
Session.Abandon()
will end the current session.Session_End
will be fired and the next request will fire theSession_Start
event.Session.Clear
will just clear the session data and the the session will remain alive.Session ID will remain the same in both cases, as long as the browser is not closed.
In a nutshell:
Session.Abandon();
cancels the currentSession
.Session.Clear();
clears all values fromSession
state.