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 © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有