You have to get really tricky to get this, Saar, because you can't
retrieve the ServerVariables in the Application_Sta rt 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.Curre ntDomain.Dynami cDirectory and adding a "/".
In global.asax :
Sub Application_Sta rt()
Dim MyArray() As String = Split(AppDomain .CurrentDomain. DynamicDirector y, "\")
Application("Ap p_Virtual_Dir") = ("/" & MyArray(6).ToSt ring())
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("Ap p_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.Curre ntDomain.Dynami cDirectory
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.Curre ntDomain.BaseDi rectory
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.Curre ntDomain.BaseDi rectory 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.Curre ntDomain.Dynami cDirectory'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*******@gmai l.com> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi
How can I get the application's virtual directory from the
Application_Sta rt method in Global.asax ?
Keep in mind there is no request/response object available yet in this
stage.
Thanks
Saar.