473,761 Members | 10,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting ApplicationPath (or equivelent) in Application_Sta rt handler

Is there any way I can get the application path (the one returned by
Request.Applica tionPath) in the Application_Sta rt 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 8511
Hi Bryan,

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

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

string path = HttpContext.Cur rent.Server.Map Path("~/");

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.Curre ntDomain.BaseDi rectory;

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***@newsgroup s.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Sta rt
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril. ameritech.net
68.253.201.186
| Lines: 1
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1319 92
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.Applica tionPath) in the Application_Sta rt 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.Applica tionPath 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_Sta rt
event, I think we can consider the following two means:

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

string path = HttpContext.Cur rent.Server.Map Path("~/");

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.Curre ntDomain.BaseDi rectory;

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***@newsgroup s.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Sta rt
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril. ameritech.net
68.253.201.1 86
| Lines: 1
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publ ic.dotnet.frame work.aspnet:131 992
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.Applica tionPath) in the Application_Sta rt 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_Sta rt.
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***@newsgrou ps.nospam> wrote in message
news:dm******** *************** *********@4ax.c om... Steven -
Thanks, but that's not quite what I need. If I have an ASP.NET
application called foo, Request.Applica tionPath 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_Sta rt
event, I think we can consider the following two means:

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

string path = HttpContext.Cur rent.Server.Map Path("~/");

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.Curre ntDomain.BaseDi rectory;

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***@newsgroup s.nospam
| Subject: Getting ApplicationPath (or equivelent) in Application_Sta rt
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril. ameritech.net
68.253.201.18 6
| Lines: 1
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.pub lic.dotnet.fram ework.aspnet:13 1992
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Is there any way I can get the application path (the one returned by
| Request.Applica tionPath) in the Application_Sta rt 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.Cur rent.Request
to access the HttpRequest object since Application_Sta rt is also fired by
a certain client request. However, as Juan has mentioned, generally
speaking Request is invisible in application_Sta rt 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************ **@TK2MSFTNGXA0 1.phx.gbl>
<dm************ *************** *****@4ax.com>
| Subject: Re: Getting ApplicationPath (or equivelent) in Application_Sta rt
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 222stb33.codete l.net.do 64.32.114.222
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1320 68
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| re:
| > Any way to do this?
|
| There is a way, but not from Application_Sta rt.
| 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***@newsgrou ps.nospam> wrote in message
| news:dm******** *************** *********@4ax.c om...
| > Steven -
| > Thanks, but that's not quite what I need. If I have an ASP.NET
| > application called foo, Request.Applica tionPath 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_Sta rt
| >>event, I think we can consider the following two means:
| >>
| >>1. Use the HttpContext.Cur rent.Server object 's MapPath with the "~/"
path
| >>expression to get the app root's physical path. For example:
| >>
| >>string path = HttpContext.Cur rent.Server.Map Path("~/");
| >>
| >>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.Curre ntDomain.BaseDi rectory;
| >>
| >>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***@newsgroup s.nospam
| >>| Subject: Getting ApplicationPath (or equivelent) in Application_Sta rt
| >>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.publi c.dotnet.framew ork.aspnet
| >>| NNTP-Posting-Host: adsl-68-253-201-186.dsl.emhril. ameritech.net
| >>68.253.201.18 6
| >>| Lines: 1
| >>| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| >>| Xref: TK2MSFTNGXA01.p hx.gbl
| >>microsoft.pub lic.dotnet.fram ework.aspnet:13 1992
| >>| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| >>|
| >>| Is there any way I can get the application path (the one returned by
| >>| Request.Applica tionPath) in the Application_Sta rt 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.Applica tionPath however, you may have
to access it through the HttpContext Object like:

HttpContext.Cur rent.Request.Ap plicationPath

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***@newsgrou ps.nospam> wrote in message
news:vs******** *************** *********@4ax.c om...
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************ **@TK2MSFTNGXA0 1.phx.gbl>
<dm************ *************** *****@4ax.com>
<ei************ *@tk2msftngp13. phx.gbl>
<Wp************ **@TK2MSFTNGXA0 1.phx.gbl>
<vs************ *************** *****@4ax.com>
| Subject: Re: Getting ApplicationPath (or equivelent) in Application_Sta rt
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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 222stb33.codete l.net.do 64.32.114.222
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1324 92
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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***@newsgrou ps.nospam> wrote in message
| news:vs******** *************** *********@4ax.c om...
| > 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
2392
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 application path. I need the same functionality that has ASP.NET (Request.ApplicationPath)
2
3823
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 wish to use the function "request.applicationpath" from inside my class. In solution explorer I have right clicked on the references node and added a reference to system.web.dll
11
2024
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 the image but in design time mode all variables concerning Server or Context ar not set ! ...so I can't use MapPath function to obtain the physical parth of the picture ... So my second question is how to retrieve the physical root path of the...
3
3090
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 displayed. Can anybody know this issue and help me to resolve this. In past i received the response saying that i should download the image first and then parse the actual response and modify the src attribute of the
2
2574
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 Application_Start(Object sender, EventArgs e) { string sDir = Request.ApplicationPath ; }
1
1414
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 development (running on IIS 5.1) and http://app.whatever.com/ for production (running on IIS 6.0) Both applications presently contain the exact same folder/file structure. Everything is the same. For whatever sets of reasons, the following code...
1
1292
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 "Previews" and "BW Previews". On selection of an item in the combo, the HREF of those links has to change. In the SelectScorecard.aspx page, I have the code: <script language="javascript"> function previewFile(cbo)
1
4531
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 "Previews" and "BW Previews". On selection of an item in the combo, the HREF of those links has to change. In the SelectScorecard.aspx page, I have the code: <script language="javascript"> function previewFile(cbo)
2
3626
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 returning "c:\\Inetpub\..." May I know what has gone wrong?
0
9333
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10107
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7324
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.