In the regular ASP.NET you could do this in a view to determine if the current request was from localhost:
HttpContext.Current.Request.IsLocal
B
now its
HttpContext.Connection.IsLocal
and if you need to check that outside of a controller then you take a dependency on IHttpContextAccessor to get access to it.
IHttpContextAccessor
Update based on comment:
HttpContext is intrinsically available in Views
HttpContext
@if (Context.Connection.IsLocal) { }