473,769 Members | 2,377 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 8512
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
2575
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
1415
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
1293
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
4532
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
3627
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
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10219
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
10049
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
9998
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,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
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
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.