目标:要得到尽快上运行的ASP.NET 2.2核心Web应用程序在浏览器的URL。
我试过几乎每样Startup.cs
内两轮牛车的,它确保您可以使用DI用于注册IHttpContextAccessor
以访问HttpContext
有人会说使用
var url = HttpContext?.Request?.GetDisplayUrl();
您可以在控制器使用,但是如果你去定义你看到的HttpContext是MVC中等等的ControllerBase未来..
似乎这件事,没有解决方案多个岗位。
Invoke
方法,但是如何以及在何处等..? Current URL in ASPCore Middleware?我看到,程序调用Startup.cs与.UseStartup<Startup>();
是否有可能获得访问能够最终目标得到像http://localhost:4444
网址
我所想要的 ...
var url = HttpContext?.Request?.GetDisplayUrl();
尽快展示我的URL作为在类库/启动.NET核心/ Program.cs中都会让我看看URL像http://localhost:4444
对于处理请求时,你可以尝试qazxsw POI。
一个简单的中间件象下面这样:
ASP.NET Core Middleware
对于使用 public class Startup
{
//rest code
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Use((context,next) =>
{
var url = context.Request.GetDisplayUrl();
return next.Invoke();
});
//rest code
}
}
,加
GetDisplayUrl()