You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of our update to IHostingEnvironment we have made the following changes:
Added ApplicationName, ContentRootPath and ContentRootFileProvider.
Removed Configuration and MapPath(string virtualPath)
We aim to relocate the information we provided from IApplicationEnvironment to IHostingEnvironment. This means that the fields on IApplicationEnvironment, specifically ApplicationName and ApplicationBasePath, will no longer be set. Instead, the ApplicationName will be set on the IHostingEnvironment, the application base path is stored in the ContentRootPath field and the ContentRootFileProvider is the file provider for the directory set by ContentRootPath. The extension method to configure the content root is also renamed to UseContentRoot(...).
All code using IApplicationEnvironment.ApplicationBasePath should be changed to use IHostingEnvironment.ContentRootPath.
All code using IApplicationEnvironment.ApplicationName should be changed to use IHostingEnvironment.ApplicationName
MapPath should be replaced by looking at the appropriate IFileProvider calls (see below).
For example, previously it would be:
varhost=new WebHostBuilder().UseApplicationBasePath("/path/to/content")
....Build();
...
var applicationEnvironment = host.Services.GetService<IApplicationEnvironment>();varapplicationName= applicationEnvironment.ApplicationName;varapplicationBasePath= applicationEnvironment.ApplicationBasePath;
Now, it should be changed to:
varhost=new WebHostBuilder().UseContentRoot("/path/to/content")
....Build();
...
var hostingEnvironment = host.Services.GetService<IHostingEnvironment>();varapplicationName= hostingEnvironment.ApplicationName;varcontentRootPath= hostingEnvironment.ContentRootPath;
Old (hostingEnvironment is IHostingEnvironment). The old MapPath method only worked with files inside of the webroot. To get files on the ContentRoot (where the application code and views lived) required more steps.
As part of our update to
IHostingEnvironment
we have made the following changes:ApplicationName
,ContentRootPath
andContentRootFileProvider
.Configuration
andMapPath(string virtualPath)
We aim to relocate the information we provided from
IApplicationEnvironment
toIHostingEnvironment
. This means that the fields onIApplicationEnvironment
, specificallyApplicationName
andApplicationBasePath
, will no longer be set. Instead, theApplicationName
will be set on theIHostingEnvironment
, the application base path is stored in theContentRootPath
field and theContentRootFileProvider
is the file provider for the directory set byContentRootPath
. The extension method to configure the content root is also renamed toUseContentRoot(...)
.All code using
IApplicationEnvironment.ApplicationBasePath
should be changed to useIHostingEnvironment.ContentRootPath
.All code using
IApplicationEnvironment.ApplicationName
should be changed to useIHostingEnvironment.ApplicationName
MapPath
should be replaced by looking at the appropriateIFileProvider
calls (see below).For example, previously it would be:
Now, it should be changed to:
Old (hostingEnvironment is
IHostingEnvironment
). The old MapPath method only worked with files inside of the webroot. To get files on the ContentRoot (where the application code and views lived) required more steps.IHostingEnvironment
now has 2IFileProvider
types exposed:Use aspnet/Hosting#651 for further discussions.
The text was updated successfully, but these errors were encountered: