Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get application path in asp.net vnext

I've been trying to open a file in asp.net 5 and have not been having a lot of success.

In the past you used Server.MapPath or HostingEnvironment.ApplicationPhysicalPath. They are both gone in the OWIN based framework.

There is a HostingEnvironment class but it's in the System.Aspnet but it needs to be initialized by the hosting environment (it no longer has a static member for ApplicationPhysicalPath but I'm guessing the WebRoot member does that now. The problem is I can't find a reference to it anywhere.

I've also looked at Context.GetFeature<> but it doesn't seem to have any feature that would show the application path, just request and response related info. The code listing the features can be found here.

<snark>Is the ability to work with files a discontinued feature in ASP.NET?</snark>

There is also the possibility that I can't brain very well right now and missed something.

like image 809
linkerro Avatar asked Mar 05 '15 09:03

linkerro


People also ask

What is the Wwwroot folder?

By default, the wwwroot folder in the ASP.NET Core project is treated as a web root folder. Static files can be stored in any folder under the web root and accessed with a relative path to that root.

What is my ASP.NET application?

What is ASP.NET? .NET is a developer platform made up of tools, programming languages, and libraries for building many different types of applications. ASP.NET extends the .NET developer platform with tools and libraries specifically for building web apps.

What is Server MapPath in C#?

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Is ASP NET MVC 5 Open Source?

ASP.NET MVC is a web application framework developed by Microsoft that implements the model–view–controller (MVC) pattern. It is no longer in active development. It is open-source software, apart from the ASP.NET Web Forms component, which is proprietary.


1 Answers

You can get it from the ApplicationBasePath property of Microsoft.Framework.Runtime.IApplicationEnvironment serivce.

Example: https://github.com/aspnet/Mvc/blob/9f1cb655f6bb1fa0ce1c1e3782c43a2d45ca4e37/test/WebSites/FilesWebSite/Controllers/DownloadFilesController.cs#L28

like image 140
Kiran Avatar answered Oct 06 '22 00:10

Kiran