Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current application physical path within Application_Start

Tags:

c#

asp.net

I'm not able to get the current physical path within Application_Start using

HttpContext.Current.Request.PhysicalApplicationPath

because there is no Request object at that time.

How else can I get the physical path?

like image 375
Alex Avatar asked Sep 29 '09 23:09

Alex


3 Answers

 protected void Application_Start(object sender, EventArgs e)
 {
     string path = Server.MapPath("/");
     //or 
     string path2 = Server.MapPath("~");
     //depends on your application needs

 }
like image 129
rick schott Avatar answered Nov 09 '22 19:11

rick schott


I created a website with ASP.Net WebForms where you can see the result of using all forms mentioned in previous responses from a site in Azure.

http://wfserverpaths.azurewebsites.net/

Summary:


Server.MapPath("/") => D:\home\site\wwwroot\

Server.MapPath("~") => D:\home\site\wwwroot\

HttpRuntime.AppDomainAppPath => D:\home\site\wwwroot\

HttpRuntime.AppDomainAppVirtualPath => /

AppDomain.CurrentDomain.BaseDirectory => D:\home\site\wwwroot\

HostingEnvironment.MapPath("/") => D:\home\site\wwwroot\

HostingEnvironment.MapPath("~") => D:\home\site\wwwroot\
like image 39
batressc Avatar answered Nov 09 '22 21:11

batressc


You can also use

HttpRuntime.AppDomainAppVirtualPath
like image 23
DotNetUser Avatar answered Nov 09 '22 20:11

DotNetUser