考虑网址:http://website.com/application
在早期版本的.Net中,
HttpContext.Current.Request.Url.Host = "website.com"
HttpContext.Current.Request.ApplicationPath = "/application"
在Aspnet5 RC1中,获取主机很好,但是如何获得Request.ApplicationPath
?
答案 0 :(得分:0)
使用IApplicationEnvironment
:
private readonly IApplicationEnvironment _appEnvironment;
public HomeController(IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}
public IActionResult Index()
{
var path = _appEnvironment.ApplicationBasePath;
// other codes
}