Jul 10, 2016

How to get application base directory and WWWroot path in asp.net core 1.0

Short and simple post for accessing Application base directory and wwwroot path in asp.net core 1.0.

This post is useful for newbie of asp.net core framework because many things changed from previous version of .Net framework.

IHostingEnvironment service to get both Application base directory and wwwroot. 
Let's see code example for IHostingEnvironment service.
private IHostingEnvironment _hostingEnvironment;
public ValuesController(IHostingEnvironment hostingEnvironment)
{
    _hostingEnvironment = hostingEnvironment;
}
// GET: api/values
[HttpGet]
public IEnumerable<string> Get()
{
    // _hostingEnvironment.WebRootPath -- wwroot folder path 
    // _hostingEnvironment.ContentRootPath -- Application Base Path

    return new string[] { _hostingEnvironment.WebRootPath, _hostingEnvironment.ContentRootPath };
}
It's a simple and informative post regarding asp.net core 1.0.

Hope you like it and keep reading for more!!

1 comment:

  1. This article is very useful. Great tips here. Your way is telling in this post is really very good. For more info:Techidemics

    ReplyDelete