发布:2022/12/29 15:22:19作者:管理员 来源:本站 浏览次数:547
Program.cs文件中
//获取IP使用
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Controller中
private readonly IHttpContextAccessor httpContextAccessor;
public YangController(IHttpContextAccessor _httpContextAccessor)
{
httpContextAccessor = _httpContextAccessor;
}
方法里调用
var ip=httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4