如何在Aspnet5中获取Request.ApplciationPath

时间:2016-01-08 05:06:05

标签: c# url asp.net-core asp.net-core-mvc httpcontext

考虑网址:http://website.com/application
在早期版本的.Net中,

HttpContext.Current.Request.Url.Host = "website.com"
HttpContext.Current.Request.ApplicationPath = "/application"

在Aspnet5 RC1中,获取主机很好,但是如何获得Request.ApplicationPath

1 个答案:

答案 0 :(得分:0)

使用IApplicationEnvironment

private readonly IApplicationEnvironment _appEnvironment;
public HomeController(IApplicationEnvironment appEnvironment)
{
    _appEnvironment = appEnvironment;
}
public IActionResult Index()
{
    var path = _appEnvironment.ApplicationBasePath;
    // other codes
}