You have to get really tricky to get this, Saar, because you can't
retrieve the ServerVariables in the Application_Start global.asax
event, as you correctly point out, because the Request object
is not yet available.
You can kludge the retrieval of the virtual directory by splitting
AppDomain.CurrentDomain.DynamicDirectory and adding a "/".
In global.asax :
Sub Application_Start()
Dim MyArray() As String = Split(AppDomain.CurrentDomain.DynamicDirectory, "\")
Application("App_Virtual_Dir") = ("/" & MyArray(6).ToString())
End Sub
In your retrieval page :
<%@ Page Language="VB" EnableViewState="false" %>
<script runat="server">
Sub Page_Load(obj as object, e as eventargs)
Dim AppDir as String = Application("App_Virtual_Dir")
lblMessage.Text = AppDir
End Sub
</script>
<html>
<body>
<asp:Label id="lblMessage" runat="server"/></asp:Label> <br />
</body>
</html>
---000---
This works because AppDomain.CurrentDomain.DynamicDirectory
has a fixed path which includes the virtual directory name, which will
always be in the 7th spot. ( Remember, VB.NET uses zero-based Arrays. )
You could, alternately, split AppDomain.CurrentDomain.BaseDirectory
and, if your physical directory is named the same as your virtual directory,
you could retrieve the name and prepend a forward slash to compose your
virtual path.
Splitting AppDomain.CurrentDomain.BaseDirectory would need trial and error,
though, because the physical directory may be deep in the wwwroot directory
tree, or even outside the wwwroot tree, and the number of subdirectories might
vary, while the AppDomain.CurrentDomain.DynamicDirectory's path is fixed
and the MyArray(6) position will always return just the name of the virtual
directory, needing only the prepended "/" to complete the virtual path.
Good luck !
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
"Saar Carmi" <sa*******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com...
Hi
How can I get the application's virtual directory from the
Application_Start method in Global.asax ?
Keep in mind there is no request/response object available yet in this
stage.
Thanks
Saar.