473,394 Members | 1,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Getting ApplicationPath (or equivelent) in Application_Start handler

Is there any way I can get the application path (the one returned by
Request.ApplicationPath) in the Application_Start method in
Global.asax? Request is not valid there. On a related note, is there a
way to get it from a static method in an aspx page, or in the class
(static) constructor for an aspx page?

Thanks,
Bryan
Nov 19 '05 #1
8 8463
Hi Bryan,

Welcome to ASPNET newsgroup.
As for getting asp.net application's root app path in Application_Start
event, I think we can consider the following two means:

1. Use the HttpContext.Current.Server object 's MapPath with the "~/" path
expression to get the app root's physical path. For example:

string path = HttpContext.Current.Server.MapPath("~/");

2. AS far as in the 1.x version, since each asp.net application is hosted
in a single .net APPDomain, and the AppDomain's BaseDirectory is set as the
Asp.net application's web root, so we can also use the following statement
to get the application's base dir also:

string basedir = AppDomain.CurrentDomain.BaseDirectory;

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: br***@newsgroups.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Start
handler
| Date: Tue, 18 Oct 2005 00:10:48 -0500
| Message-ID: <qn********************************@4ax.com>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril.ameritech.net
68.253.201.186
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:131992
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.ApplicationPath) in the Application_Start method in
| Global.asax? Request is not valid there. On a related note, is there a
| way to get it from a static method in an aspx page, or in the class
| (static) constructor for an aspx page?
|
| Thanks,
| Bryan
|

Nov 19 '05 #2
Steven -
Thanks, but that's not quite what I need. If I have an ASP.NET
application called foo, Request.ApplicationPath returs /foo. I'm not
looking for the physical path on the machine, but the name of the
virtual application root. Any way to do this?

Thanks,
Bryan

On Tue, 18 Oct 2005 08:20:26 GMT, st*****@online.microsoft.com (Steven
Cheng[MSFT]) wrote:
Hi Bryan,

Welcome to ASPNET newsgroup.
As for getting asp.net application's root app path in Application_Start
event, I think we can consider the following two means:

1. Use the HttpContext.Current.Server object 's MapPath with the "~/" path
expression to get the app root's physical path. For example:

string path = HttpContext.Current.Server.MapPath("~/");

2. AS far as in the 1.x version, since each asp.net application is hosted
in a single .net APPDomain, and the AppDomain's BaseDirectory is set as the
Asp.net application's web root, so we can also use the following statement
to get the application's base dir also:

string basedir = AppDomain.CurrentDomain.BaseDirectory;

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: br***@newsgroups.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Start
handler
| Date: Tue, 18 Oct 2005 00:10:48 -0500
| Message-ID: <qn********************************@4ax.com>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril.ameritech.net
68.253.201.186
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:131992
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.ApplicationPath) in the Application_Start method in
| Global.asax? Request is not valid there. On a related note, is there a
| way to get it from a static method in an aspx page, or in the class
| (static) constructor for an aspx page?
|
| Thanks,
| Bryan
|

Nov 19 '05 #3
re:
Any way to do this?
There is a way, but not from Application_Start.
As you already know, the Request object is not available in it.

Can you use the Init event ? ( Overriding it with OnInit ), or the Page_Load event ?
Either of them would allow you to Request the application's virtual path.

Also, unless you want the data to be portable to other boxes, you could
simply set an Application variable which holds the Application's virtual path
( kinda klunky, I know, but it would get the job done... ).


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<br***@newsgroups.nospam> wrote in message
news:dm********************************@4ax.com... Steven -
Thanks, but that's not quite what I need. If I have an ASP.NET
application called foo, Request.ApplicationPath returs /foo. I'm not
looking for the physical path on the machine, but the name of the
virtual application root. Any way to do this?

Thanks,
Bryan

On Tue, 18 Oct 2005 08:20:26 GMT, st*****@online.microsoft.com (Steven
Cheng[MSFT]) wrote:
Hi Bryan,

Welcome to ASPNET newsgroup.
As for getting asp.net application's root app path in Application_Start
event, I think we can consider the following two means:

1. Use the HttpContext.Current.Server object 's MapPath with the "~/" path
expression to get the app root's physical path. For example:

string path = HttpContext.Current.Server.MapPath("~/");

2. AS far as in the 1.x version, since each asp.net application is hosted
in a single .net APPDomain, and the AppDomain's BaseDirectory is set as the
Asp.net application's web root, so we can also use the following statement
to get the application's base dir also:

string basedir = AppDomain.CurrentDomain.BaseDirectory;

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: br***@newsgroups.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Start
handler
| Date: Tue, 18 Oct 2005 00:10:48 -0500
| Message-ID: <qn********************************@4ax.com>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril.ameritech.net
68.253.201.186
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:13199 2
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.ApplicationPath) in the Application_Start method in
| Global.asax? Request is not valid there. On a related note, is there a
| way to get it from a static method in an aspx page, or in the class
| (static) constructor for an aspx page?
|
| Thanks,
| Bryan
|

Nov 19 '05 #4
Hi Bryan,

Thanks for your response.
Based on my further test, we can try using the HttpContext.Current.Request
to access the HttpRequest object since Application_Start is also fired by
a certain client request. However, as Juan has mentioned, generally
speaking Request is invisible in application_Start event, you'd better add
some code to check whether the HttpContext's member property being null so
as to insure no exception will occured. Also, if possible, you can
consider Juan's suggestion on move the App Path query to Page's certain
event (cache them once).

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Juan T. Llibre" <no***********@nowhere.com>
| References: <qn********************************@4ax.com>
<cw**************@TK2MSFTNGXA01.phx.gbl>
<dm********************************@4ax.com>
| Subject: Re: Getting ApplicationPath (or equivelent) in Application_Start
handler
| Date: Tue, 18 Oct 2005 08:53:17 -0400
| Lines: 94
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <ei*************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222stb33.codetel.net.do 64.32.114.222
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132068
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| re:
| > Any way to do this?
|
| There is a way, but not from Application_Start.
| As you already know, the Request object is not available in it.
|
| Can you use the Init event ? ( Overriding it with OnInit ), or the
Page_Load event ?
| Either of them would allow you to Request the application's virtual path.
|
| Also, unless you want the data to be portable to other boxes, you could
| simply set an Application variable which holds the Application's virtual
path
| ( kinda klunky, I know, but it would get the job done... ).
|
|
|
|
| Juan T. Llibre, ASP.NET MVP
| ASP.NET FAQ : http://asp.net.do/faq/
| Foros de ASP.NET en Español : http://asp.net.do/foros/
| ======================================
| <br***@newsgroups.nospam> wrote in message
| news:dm********************************@4ax.com...
| > Steven -
| > Thanks, but that's not quite what I need. If I have an ASP.NET
| > application called foo, Request.ApplicationPath returs /foo. I'm not
| > looking for the physical path on the machine, but the name of the
| > virtual application root. Any way to do this?
| >
| > Thanks,
| > Bryan
| >
| > On Tue, 18 Oct 2005 08:20:26 GMT, st*****@online.microsoft.com (Steven
| > Cheng[MSFT]) wrote:
| >>Hi Bryan,
| >>
| >>Welcome to ASPNET newsgroup.
| >>As for getting asp.net application's root app path in Application_Start
| >>event, I think we can consider the following two means:
| >>
| >>1. Use the HttpContext.Current.Server object 's MapPath with the "~/"
path
| >>expression to get the app root's physical path. For example:
| >>
| >>string path = HttpContext.Current.Server.MapPath("~/");
| >>
| >>2. AS far as in the 1.x version, since each asp.net application is
hosted
| >>in a single .net APPDomain, and the AppDomain's BaseDirectory is set as
the
| >>Asp.net application's web root, so we can also use the following
statement
| >>to get the application's base dir also:
| >>
| >>string basedir = AppDomain.CurrentDomain.BaseDirectory;
| >>
| >>Hope helps. Thanks,
| >>
| >>Steven Cheng
| >>Microsoft Online Support
| >>
| >>Get Secure! www.microsoft.com/security
| >>(This posting is provided "AS IS", with no warranties, and confers no
| >>rights.)
| >>
| >>
| >>
| >>
| >>
| >>--------------------
| >>| From: br***@newsgroups.nospam
| >>| Subject: Getting ApplicationPath (or equivelent) in Application_Start
| >>handler
| >>| Date: Tue, 18 Oct 2005 00:10:48 -0500
| >>| Message-ID: <qn********************************@4ax.com>
| >>| X-Newsreader: Forte Agent 3.1/32.783
| >>| MIME-Version: 1.0
| >>| Content-Type: text/plain; charset=us-ascii
| >>| Content-Transfer-Encoding: 7bit
| >>| Newsgroups: microsoft.public.dotnet.framework.aspnet
| >>| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril.ameritech.net
| >>68.253.201.186
| >>| Lines: 1
| >>| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| >>| Xref: TK2MSFTNGXA01.phx.gbl
| >>microsoft.public.dotnet.framework.aspnet:13199 2
| >>| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| >>|
| >>| Is there any way I can get the application path (the one returned by
| >>| Request.ApplicationPath) in the Application_Start method in
| >>| Global.asax? Request is not valid there. On a related note, is there a
| >>| way to get it from a static method in an aspx page, or in the class
| >>| (static) constructor for an aspx page?
| >>|
| >>| Thanks,
| >>| Bryan
| >>|
|
|
|

Nov 19 '05 #5
Steven, Juan -
Thanks for the insights. Between Page_Load and a static
constructor, I can make it work just fine.

Cheers,
Bryan

Nov 19 '05 #6
You should be able to use Request.ApplicationPath however, you may have
to access it through the HttpContext Object like:

HttpContext.Current.Request.ApplicationPath

Nov 19 '05 #7
Good news !

Glad you found a solution...

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<br***@newsgroups.nospam> wrote in message
news:vs********************************@4ax.com...
Steven, Juan -
Thanks for the insights. Between Page_Load and a static
constructor, I can make it work just fine.

Cheers,
Bryan

Nov 19 '05 #8
Cheers Bryan,

Have a good day!
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Juan T. Llibre" <no***********@nowhere.com>
| References: <qn********************************@4ax.com>
<cw**************@TK2MSFTNGXA01.phx.gbl>
<dm********************************@4ax.com>
<ei*************@tk2msftngp13.phx.gbl>
<Wp**************@TK2MSFTNGXA01.phx.gbl>
<vs********************************@4ax.com>
| Subject: Re: Getting ApplicationPath (or equivelent) in Application_Start
handler
| Date: Wed, 19 Oct 2005 12:12:05 -0400
| Lines: 20
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OH**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 222stb33.codetel.net.do 64.32.114.222
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:132492
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Good news !
|
| Glad you found a solution...
|
|
|
| Juan T. Llibre, ASP.NET MVP
| ASP.NET FAQ : http://asp.net.do/faq/
| Foros de ASP.NET en Español : http://asp.net.do/foros/
| ======================================
| <br***@newsgroups.nospam> wrote in message
| news:vs********************************@4ax.com...
| > Steven, Juan -
| > Thanks for the insights. Between Page_Load and a static
| > constructor, I can make it work just fine.
| >
| > Cheers,
| > Bryan
|
|
|

Nov 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Vadym Stetsyak | last post by:
Hi, All! For example if I have http://server/myvirtualpath/someotherpath/page.asp and virtual path on the IIS is http://server/myvirtualpath How can I retrieve above mentioned asp...
2
by: martin | last post by:
Hi, I am developing a class to help my asp.net application along. The class is part of a seperate project although this project is included in the same solution as my main web application. I...
11
by: KarimL | last post by:
Thanks for your advices... but i need to get the Image height because i dynamically resize the height of my webcontrol based on the image height. More i just have the url (relative parth) to the...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
2
by: ad | last post by:
I want to get the Application path, I use the code: string sDir = Request.ApplicationPath ; It run well in code behind, but if I place the code above in Global.asax like: void...
1
by: James | last post by:
I have a testing/development environment and a production environment for an ASP.NET application. The URLs end up being similar to the following: http://www.whatever.com/folder/appname for...
1
by: Radu | last post by:
Hi. I have a page, named "SelectScorecard", which contains a combo and some links to outside documents, on the server. These documents are situated in some sub-folders of the webfolder, named...
1
by: Radu | last post by:
Hi. I have a page, named "SelectScorecard", which contains a combo and some links to outside documents, on the server. These documents are situated in some sub-folders of the webfolder, named...
2
by: CKKwan | last post by:
Dear All, Using VS2008 on Vista (IIS7). Request.ApplicationPath return something like "http://localhost:50440/" When deploy into Server 2003 (IIS6), found that Request.ApplicationPath is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.