473,499 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8470
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
2377
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
3787
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
2005
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
3054
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
2554
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
1403
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
1285
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
4513
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
3595
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
7128
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
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7169
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
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.