我们目前正在重写/转换我们的ASP。NET WebForms应用程序使用ASP。净的核心。尽量避免重新设计。
有一节我们在类库中使用HttpContext来检查当前状态。如何访问HttpContext。当前的。net Core 1.0?
var current = HttpContext.Current;
if (current == null)
{
// do something here
// string connection = Configuration.GetConnectionString("MyDb");
}
我需要访问这个,以构建当前的应用程序主机。
$"{current.Request.Url.Scheme}://{current.Request.Url.Host}{(current.Request.Url.Port == 80 ? "" : ":" + current.Request.Url.Port)}";