如何获取当前网址? 我试着这样说:
Program.cs的
var location = new Uri($"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}");
或
public string BuildAbsolute(PathString path, QueryString query = default(QueryString), FragmentString fragment = default(FragmentString))
{
var rq = HttpContent.Request;
return Microsoft.AspNetCore.Http.Extensions.UriHelper.BuildAbsolute(rq.Scheme, rq.Host, rq.PathBase, path, query, fragment);
}
Visual Studio找不到"请求"
我唯一需要的是获取当前的URL和主机/路径
答案 0 :(得分:1)
您可以使用中间件在Configure内部的Startup.cs中运行您的功能。你可以做到
app.Use(async (context,next)=>{
//Do what you want with context,which is HttpContext
await next.Invoke();
});