Physical Application Path in Application_End

  • Thread starter Alphonse Giambrone
  • Start date
A

Alphonse Giambrone

How can I get the physical application path in the Application_End event?
I need it to periodically compact a database and it seems that the request,
application and server objects are not available at that point.
 
M

Mike Moore [MSFT]

Hi Alphonse,

Here's one way to do it. Place these functions in your global.asax file.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Application("path") = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
'To get the string, just use Application("path")
Dim s As String = Application("path")

'Since you can't watch the application end event,
'this code writes the string to a file where you
'can see it. This is only for test purposes and
'you will need to temporarily grant the ASPNET
'account full permissions to the folder, in this
'case C:\Inetpub\wwwroot\test1.
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test.txt")
file.WriteLine(s)
file.Close()
End Sub

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
A

Alphonse Giambrone

Thanks for the quick reply Mike.
Based on this, is seems I have misidentified the location of my problem.
I do store the value in an application variable, but because I use it in
several places in the app, I retrieve it from a public function in another
module via HttpContext.Current.Application("path"). This was the only method
I found to gain access to application variables in a module or class.
In Application_End I am actually calling a function in another module that
is compacting the db and updating a field in the db. This function retrieves
the path from the other function.
I knew it was failing due to not being able to retrieve Application("path")
so I incorrectly assumed that application vars were not available in
Application_End.
After trying your example, I see that I was wrong and my real problem is
that they are not available in another module/class once Application_End
fires via HttpContext.Current.Application since it is nothing at that time.

So, what I really need is a method to access the application variables from
another module or class once Application_End fires.
Is this possible?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


"Mike Moore [MSFT]" said:
Hi Alphonse,

Here's one way to do it. Place these functions in your global.asax file.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Application("path") = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
'To get the string, just use Application("path")
Dim s As String = Application("path")

'Since you can't watch the application end event,
'this code writes the string to a file where you
'can see it. This is only for test purposes and
'you will need to temporarily grant the ASPNET
'account full permissions to the folder, in this
'case C:\Inetpub\wwwroot\test1.
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test.txt")
file.WriteLine(s)
file.Close()
End Sub

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
Reply-To: "Alphonse Giambrone" <[email protected]>
From: "Alphonse Giambrone" <[email protected]>
Subject: Physical Application Path in Application_End
Date: Tue, 6 Jan 2004 15:59:25 -0500
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:200127
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

How can I get the physical application path in the Application_End event?
I need it to periodically compact a database and it seems that the request,
application and server objects are not available at that point.
 
M

Mike Moore [MSFT]

Hi Alphonse,

My first recommendation is to extract the values from the application
object from within the Application_End event. Then pass the values as
parameters.

I also tried a public variable in a module and it worked. Here's the code.

Public Class Global
Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Module1.AppPath = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
Module1.WriteAppVar()
End Sub
End Class

Module Module1

Public AppPath As String

Public Sub WriteAppVar()
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test2.txt")
file.WriteLine(AppPath)
file.Close()
End Sub
End Module

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
Reply-To: "Alphonse Giambrone" <[email protected]>
From: "Alphonse Giambrone" <[email protected]>
References: <[email protected]>
Subject: Re: Physical Application Path in Application_End
Date: Tue, 6 Jan 2004 21:18:48 -0500
Lines: 106
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:200202
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Thanks for the quick reply Mike.
Based on this, is seems I have misidentified the location of my problem.
I do store the value in an application variable, but because I use it in
several places in the app, I retrieve it from a public function in another
module via HttpContext.Current.Application("path"). This was the only method
I found to gain access to application variables in a module or class.
In Application_End I am actually calling a function in another module that
is compacting the db and updating a field in the db. This function retrieves
the path from the other function.
I knew it was failing due to not being able to retrieve Application("path")
so I incorrectly assumed that application vars were not available in
Application_End.
After trying your example, I see that I was wrong and my real problem is
that they are not available in another module/class once Application_End
fires via HttpContext.Current.Application since it is nothing at that time.

So, what I really need is a method to access the application variables from
another module or class once Application_End fires.
Is this possible?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


"Mike Moore [MSFT]" said:
Hi Alphonse,

Here's one way to do it. Place these functions in your global.asax file.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Application("path") = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
'To get the string, just use Application("path")
Dim s As String = Application("path")

'Since you can't watch the application end event,
'this code writes the string to a file where you
'can see it. This is only for test purposes and
'you will need to temporarily grant the ASPNET
'account full permissions to the folder, in this
'case C:\Inetpub\wwwroot\test1.
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test.txt")
file.WriteLine(s)
file.Close()
End Sub

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
Reply-To: "Alphonse Giambrone" <[email protected]>
From: "Alphonse Giambrone" <[email protected]>
Subject: Physical Application Path in Application_End
Date: Tue, 6 Jan 2004 15:59:25 -0500
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
 
A

Alphonse Giambrone

Thanks Mike.
That will work.
Just for my knowledge. Am I correct in that you are confirming that
application variables are not available outside global.asax once
Application_End has fired?
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


"Mike Moore [MSFT]" said:
Hi Alphonse,

My first recommendation is to extract the values from the application
object from within the Application_End event. Then pass the values as
parameters.

I also tried a public variable in a module and it worked. Here's the code.

Public Class Global
Inherits System.Web.HttpApplication

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Module1.AppPath = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
Module1.WriteAppVar()
End Sub
End Class

Module Module1

Public AppPath As String

Public Sub WriteAppVar()
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test2.txt")
file.WriteLine(AppPath)
file.Close()
End Sub
End Module

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.
Subject: Re: Physical Application Path in Application_End
Date: Tue, 6 Jan 2004 21:18:48 -0500
Lines: 106
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:200202
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Thanks for the quick reply Mike.
Based on this, is seems I have misidentified the location of my problem.
I do store the value in an application variable, but because I use it in
several places in the app, I retrieve it from a public function in another
module via HttpContext.Current.Application("path"). This was the only method
I found to gain access to application variables in a module or class.
In Application_End I am actually calling a function in another module that
is compacting the db and updating a field in the db. This function retrieves
the path from the other function.
I knew it was failing due to not being able to retrieve Application("path")
so I incorrectly assumed that application vars were not available in
Application_End.
After trying your example, I see that I was wrong and my real problem is
that they are not available in another module/class once Application_End
fires via HttpContext.Current.Application since it is nothing at that time.

So, what I really need is a method to access the application variables from
another module or class once Application_End fires.
Is this possible?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


"Mike Moore [MSFT]" said:
Hi Alphonse,

Here's one way to do it. Place these functions in your global.asax file.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim di As System.IO.DirectoryInfo
di = System.IO.Directory.GetParent(Server.MapPath("web.config"))
Application("path") = di.FullName
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
'To get the string, just use Application("path")
Dim s As String = Application("path")

'Since you can't watch the application end event,
'this code writes the string to a file where you
'can see it. This is only for test purposes and
'you will need to temporarily grant the ASPNET
'account full permissions to the folder, in this
'case C:\Inetpub\wwwroot\test1.
Dim file As New
System.IO.StreamWriter("C:\Inetpub\wwwroot\test1\test.txt")
file.WriteLine(s)
file.Close()
End Sub

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
Reply-To: "Alphonse Giambrone" <[email protected]>
From: "Alphonse Giambrone" <[email protected]>
Subject: Physical Application Path in Application_End
Date: Tue, 6 Jan 2004 15:59:25 -0500
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: ool-4352027f.dyn.optonline.net 67.82.2.127
Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top