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.
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 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.
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With